Memory leak

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
cheparukhin
Posts: 2
Joined: 2015-07-27T07:50:21-07:00
Authentication code: 1151

Memory leak

Post 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.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Memory leak

Post 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?
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
cheparukhin
Posts: 2
Joined: 2015-07-27T07:50:21-07:00
Authentication code: 1151

Re: Memory leak

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

Re: Memory leak

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