magick++ do not release memory as expected

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
collinmsn
Posts: 4
Joined: 2012-03-14T21:32:34-07:00
Authentication code: 8675308

magick++ do not release memory as expected

Post 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;
}
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: magick++ do not release memory as expected

Post 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.
Post Reply