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
memory leak when resize gif
memory leak when resize gif
Last edited by luwenbin on 2010-03-03T19:42:33-07:00, edited 1 time in total.
Re: memory leak when resize gif
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
Re: memory leak when resize gif
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!
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!