Page 1 of 1

Memory leak

Posted: 2015-07-27T08:06:39-07:00
by cheparukhin
I have a memory leak problem, which appears while consequently decoding millions of images. If memory limit is not set, the memory footprint of the program gradually increases. If the memory limit is set, after a big number of decoded images the pixel cache becomes exhausted and ImageMagick begins to throw exceptions: CacheResourcesExhausted `' @ error/cache.c/OpenPixelCache/3642.

I'm using Magick++ interface of version 6.9.1-5.

Re: Memory leak

Posted: 2015-07-27T08:24:50-07:00
by dlemstra
How you know that ImageMagick is leaking the memory? Is it possible that your program forgets to free some resources? And can you create an example program in C++ that demonstrates this behavior? You can use one of the internal image formats to read as an image (e.g. logo:) and you can write to our 'null:' image to avoid the need for images.

It is also possible that one of the delegates (e.g libjpeg-turbo/libpng) is leaking memory. What is your OS and are you linking with the latest version of those libraries?

Re: Memory leak

Posted: 2015-07-27T08:43:14-07:00
by cheparukhin
I have a strong suspicion that ImageMagick is the source of the problem because of the following reasons:

1. The same program worked without leaks before, when we used OpenCV for image decoding instead of ImageMagick. The problem occurred right after we switched from OpenCV to ImageMagick.

2. Pixel cache exceptions mean that the problem is in the ImageMagick pixel cache.

3. The problem presents itself on different systems (Ubuntu and CentOS) with different versions of libjpeg and libpng.

Re: Memory leak

Posted: 2015-07-27T11:24:30-07:00
by magick
Are you deleting any images after they are used? This should free up memory. Magick++ destructors should do this automatically when the image goes out of scope.

Post the results of this command:
  • valgrind --leak-check=full --leak-check=full --show-leak-kinds=all myMagick++
Where mymagick++ is the name of your program. For the leaks that show, are any of them traceable to Magick++ or MagickCore?

We need to reproduce the problem before we can comment further. Do you have a small example Magick++ program we can run that leaks memory? We can use valgrind to identify the source of the leak. We did try valgrind against the Magick++ unit tests and demos and they did not report any leaks.