Memory usage problem

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
Mihran
Posts: 2
Joined: 2012-09-07T08:50:41-07:00
Authentication code: 67789

Memory usage problem

Post by Mihran » 2012-09-11T04:47:07-07:00

Hi everyone!

I have folowing code.

i

Code: Select all

nt main(int argc, char *argv[]) 
{
    Image* arr[256];
    
    for(int i = 0; i < 256; i++)
    {
        Image* t = new Image(_pictures_background);
        t->read("files/1.png");
        arr[i] = t;
    }        
    std::string str;
    cout << "Memory allocated. Press enter key to continue...";
    cin >> str;
    
    for(int i = 0; i < 256; i++)
    {        
        delete arr[i];
        arr[i] = NULL;
    }
     
    cout << "Memory deallocated. Press enter key to continue...";
    cin >> str;
    return 0;
}
At first it allocates aprox. 2Gb of memory, when I delete created images memory is not actualy freed, process still use 2Gb of memory. Valgrind shows what that memory still rechable.
How can I free that memory?

Thanks in advice!

User avatar
magick
Site Admin
Posts: 10995
Joined: 2003-05-31T11:32:55-07:00

Re: Memory usage problem

Post by magick » 2012-09-11T04:54:34-07:00

You can force the image pixels to disk rather than memory with cacheThreshold(). It will be slower but the memory footprint will be smaller.

Its up to the compiler and OS to return memory after its freed. A garbage collection cycle may needed and even then the OS may not return it. Linux, for example, generally will only return large chunks of memory but keep smaller chunks even when its freed (sbrk).

Mihran
Posts: 2
Joined: 2012-09-07T08:50:41-07:00
Authentication code: 67789

Re: Memory usage problem

Post by Mihran » 2012-09-11T05:04:12-07:00

Thanks for replay.

I have a filling that it is not OS related issue. Looks like IM use its own memory allocation mechanism. And it is not free it it and keep it for reuse. I don`t want to use cache it is to slow for my case(I`m processing 100s of images ).

Post Reply