Page 1 of 1

magick++ do not release memory as expected

Posted: 2013-01-09T00:33:28-07:00
by collinmsn
hi Magick,
I have a large gif file (about 15M) which requires more memory than the resource limit setting in policy.xml. So an exception is thrown when processing this file. After that the memory allocated by magick is not released as expected. The policy.xml, c++ code, compile script and sample image can be downloaded here. https://www.dropbox.com/sh/3esh3go7x19j ... memory.zip

following is code snip

Code: Select all

int main(int argc, const char* argv[]) {
if (argc != 2) {
printf("usage: %s /path/to/image/file\n", argv[0]);
return 0;
}
MagickCore::ResourceComponentGenesis();
{
std::string data;
if (!PrepareImageData(argv[1], data)) {
return 0;
}
// process image
foo(data);
// when goes to this line,
// memory is expected to have been released
// but that's not the fact.
int ttt = 0; 
}
return 0;
}

Re: magick++ do not release memory as expected

Posted: 2013-01-09T11:25:48-07:00
by magick
Valgrind reports no memory lost when your program exits:

Code: Select all

=26426== HEAP SUMMARY:
==26426==     in use at exit: 2,841 bytes in 10 blocks
==26426==   total heap usage: 24,277 allocs, 24,267 frees, 5,177,864,641 bytes allocated
==26426== 
==26426== LEAK SUMMARY:
==26426==    definitely lost: 0 bytes in 0 blocks
==26426==    indirectly lost: 0 bytes in 0 blocks
==26426==      possibly lost: 0 bytes in 0 blocks
==26426==    still reachable: 2,841 bytes in 10 blocks
==26426==         suppressed: 0 bytes in 0 blocks
==26426== Reachable blocks (those to which a pointer was found) are not shown.
==26426== To see them, rerun with: --leak-check=full --show-reachable=yes
==26426== 
==26426== For counts of detected and suppressed errors, rerun with: -v
==26426== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)
The few bytes that are still reachable are from the dynamic module loader, libltdl.

ImageMagick reclaims all its memory on program exit. Within your loop there will be some memory usage from structures ImageMagick uses for managing resources. Also, memory allocators do not always return memory to the system, even if its freed.