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.
Memory leak
Re: Memory leak
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?
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?
-
- Posts: 2
- Joined: 2015-07-27T07:50:21-07:00
- Authentication code: 1151
Re: Memory leak
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.
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
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:
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 the results of this command:
- valgrind --leak-check=full --leak-check=full --show-leak-kinds=all myMagick++
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.