memory leak when resize gif

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
luwenbin

memory leak when resize gif

Post by luwenbin »

I found that if the gif file contains lots of frames, seems that some memory did not release after resized.Here is the simple code
list<Image> imageList;
list<Image> coalescedList;
readImages(&imageList, src);
coalesceImages(&coalescedList, imageList.begin(), imageList.end());
list<Image>::iterator it = coalescedList.begin();
string size = "300x200";
while(it != coalescedList.end()){
Image& image = (*it);
image.filterType(BoxFilter);//using a easy filter
image.zoom(size);
image.quality(90);
++it;
}
writeImages(coalescedList.begin(), coalescedList.end(),dst);
cout<<"resize gif finish"<<endl;
char c;
cin>>c;

the original gif file is here "http://fmn.xnimg.cn/fmn041/20100304/085 ... gif",which contains 193 frames
when the program print "resize gif finish", I see the process using about 500M memory and don't release after a long time. I don't know this is a bug or ImageMagick use a memory pool, if it use
a memory pool. then is there any method to release the memory as soon as possible? Thanks very much
Last edited by luwenbin on 2010-03-03T19:42:33-07:00, edited 1 time in total.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: memory leak when resize gif

Post by magick »

We're using ImageMagick 6.6.0-0 and we ran valgrind against your image. It shows there are no memory leaks:
  • valgrind convert p_large_zNIe_025e00000e9c2d13.gif null:
    ...
    ==22023== LEAK SUMMARY:
    ==22023== definitely lost: 0 bytes in 0 blocks
    ==22023== indirectly lost: 0 bytes in 0 blocks
    ==22023== possibly lost: 0 bytes in 0 blocks
luwenbin

Re: memory leak when resize gif

Post by luwenbin »

Thanks for your quick reply.
But when I use "ps aufx" command, I can see that the process still hold about 500M memory
And if I put the resize code into a loop, looks like
int resizeGif(string src, string dst){
list<Image> imageList;
list<Image> coalescedList;
readImages(&imageList, src);
coalesceImages(&coalescedList, imageList.begin(), imageList.end());
list<Image>::iterator it = coalescedList.begin();
string size = "300x200";
while(it != coalescedList.end()){
Image& image = (*it);
image.filterType(BoxFilter);//using a easy filter
image.zoom(size);
image.quality(90);
++it;
}
writeImages(coalescedList.begin(), coalescedList.end(),dst);
}

int main(int argc, char* argv[]){
int count = atoi(argv[1]);
for(int i=0; i<count; i++){
resizeGif(argv[2], argv[3]);
}
cout<<"resize gif finish"<<endl;
char c;
cin>>c;
return 0;
}

if resize once, the "ps aufx" result is "root 21598 37.5 4.0 449128 334384 pts/0 Sl+ 10:53 0:48", hold 4% memory
if resize twice, the "ps aufx" result is "root 21694 81.0 9.5 893572 778828 pts/0 Sl+ 10:55 1:36",hold 9.5% memory
if resize three times and more, the process always hold 9.5% memory. So I think it is not memory leak, seems use memory pool.
If I want to release the memory as soon as possible, is there any method?
Thanks very much!
Post Reply