What is the proper way to uninitialize ImageMagick with Magick++?
Posted: 2014-12-05T08:34:01-07:00
Hello,
This is my first time post to this forum and I am a beginner ImageMagick/Magick++ user. I searched the forum for "InitializeMagick" and it found only one post at this time (that did not answer my question).
I am using Magick++ in a C++ program successfully to resize images. I am currently doing stability and performance testing and this is one of the tests that I do (to search for memory leaks):
In the Magick++ API documentation at the following URL:
http://www.imagemagick.org/Magick++/
it states the following:
Note in the MagickCore interface, there is a method to initialize and uninitialize the ImageMagick library:
http://www.imagemagick.org/api/magick.php
I seem to recall from the valgrind dump (which I do not have in front of me at the moment), that a call to Magick++'s InitializeMagick is actually calling MagickCoreGenesis from MagickCore. So I am guessing that I am missing the matching MagickCoreTerminus call (but I don't see any way to get to it via the Magick++ API).
Does Magick++ require proper stack unrolling where InitializeMagick was called? I am guessing that, because I am using a signal handler to terminate the process, that the main's stack (that called InitializeMagick) is not being "properly unrolled".
Here is some pseudo code as to what I am doing (as I do not have the code in front of me). Note that I have several C++ programs that work like this with absolutely no memory leak when they exit via a signal handler. Currently, only the ones that are using Magick++ have memory leaks when they exit.
Should I mix MagickCore and Magick++? I'm thinking to try my next test where I use MagickCore in main to call MagickCoreGenesis, and then call MagickCoreTerminus in the signal handler. The thread that does image resizing should still be able to use Magick++.
Sorry that I don't have any of the valgrind output in front of me at the moment. I can get this later today.
Many thanks!
This is my first time post to this forum and I am a beginner ImageMagick/Magick++ user. I searched the forum for "InitializeMagick" and it found only one post at this time (that did not answer my question).
I am using Magick++ in a C++ program successfully to resize images. I am currently doing stability and performance testing and this is one of the tests that I do (to search for memory leaks):
- - run the program via valgrind for several hours, resizing images
- stop the program via a signal
- inspect the valgrind output for memory leaks
In the Magick++ API documentation at the following URL:
http://www.imagemagick.org/Magick++/
it states the following:
I am doing this, but the documentation does not explain how Magick++ uninitializes ImageMagick.Be sure to to initialize the ImageMagick library prior to using the Magick++ library ... the InitializeMagick() function call.
Note in the MagickCore interface, there is a method to initialize and uninitialize the ImageMagick library:
http://www.imagemagick.org/api/magick.php
I seem to recall from the valgrind dump (which I do not have in front of me at the moment), that a call to Magick++'s InitializeMagick is actually calling MagickCoreGenesis from MagickCore. So I am guessing that I am missing the matching MagickCoreTerminus call (but I don't see any way to get to it via the Magick++ API).
Does Magick++ require proper stack unrolling where InitializeMagick was called? I am guessing that, because I am using a signal handler to terminate the process, that the main's stack (that called InitializeMagick) is not being "properly unrolled".
Here is some pseudo code as to what I am doing (as I do not have the code in front of me). Note that I have several C++ programs that work like this with absolutely no memory leak when they exit via a signal handler. Currently, only the ones that are using Magick++ have memory leaks when they exit.
Code: Select all
void signalHandler(int signum) {
// shutdown all of the running threads gracefully
exit(1); // this is the exit that causes process termination
}
int main (int argc, char** argv) {
// I am guessing that this never goes "off the stack" properly,
// prior to the process terminating from the exit call in signalHandler
InitializeMagick(*argv);
// register signalHandler here for SIGINT (Ctrl-C), SIGUSR1, etc signals
// start all of the threads (one of which is responsible for resizing images using Magick++)
// infinite loop here on purpose
while (true) {
sleep(1);
}
exit(1); // execution never reaches here
}
Sorry that I don't have any of the valgrind output in front of me at the moment. I can get this later today.
Many thanks!