tons of magick-XXXX files in C:\Documents and Settings

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
swiss_knife

tons of magick-XXXX files in C:\Documents and Settings

Post by swiss_knife »

I am doing some memory tests with Magick, and I am getting tons of files like:

C:\Documents and Settings\myname\Local Settings\Temp\magick-k7eu50bt
C:\Documents and Settings\myname\Local Settings\Temp\magick-kbaqoqbu

It is actually filling up my hard disk, before the memory test goes through. I cannot find posts about this. Any help would be greatly appreciated.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

ImageMagick creates temporary files for a variety of reasons. They are removed as long as the process is not killed or if a soft-signal is thrown that ImageMagick can catch. It is safe to remove these as long as you do not have any ImageMagick processes running.
Last edited by magick on 2006-07-19T20:11:01-07:00, edited 1 time in total.
swiss_knife

Post by swiss_knife »

That's a problem, because my Magick process runs for hours. After some time, I end up with hundreds of Megs of such files. What is the Magick function creating those ?

Can we prevent the creation of such files. Is there a flag telling me I can delete a specific magick-XXXX file? I am catching exceptions thrown by Magich here and there on some images. That's what causing the creation of these files?
swiss_knife

Post by swiss_knife »

Can we prevent the creation of such files ??? It must have a way. It is kind of understandable that the creation of such files is a problem if a user kill my process once in a while.
Thank you.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

ImageMagick has a need to create temporary files depending on what you are doing. In some cases you can prevent them from being created. For example, you can set the resource limits such that all images are created in memory rather than disk (see http://magick.imagemagick.org/script/architecture.php for a discussion). ImageMagick will remove them if the program exits properly or if certain signals are thrown. ImageMagick, for example, intercepts the ctrl-C interrupts and remove temporary files on anything but Windows. Windows does not follow the POSIX signal specification. We did put a catch in for Windows for ctrl-C but apparently it does not work properly and we're waiting for a Windows-savvy developer to help us resolve this problem. We used to have a atexit() handler to remove the remporary files but some folks complained it was causing problems for embedded applications so we removed the atexit() call. You of course can restore it to your local version of the ImageMagick source distribution.
swiss_knife

Re: tons of magick-XXXX files in C:\Documents and Settings

Post by swiss_knife »

Thanks for this precise answer. Is this problem still in the latest Image-Magick version for Windows ? If it is, could you put the atexit() code in a #ifdef WIN32 paragraph ?? The problem is I am using Image-Magick in the application that I am selling, but my code is called in another environment where I don't have control on signals and so on, and after some time (a few weeks), the hard disk is getting filled with 611 990 KB files like magick-v4qlhq51, magick-sg2mg7u5, etc
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: tons of magick-XXXX files in C:\Documents and Settings

Post by anthony »

You could always check the date on these files and remove them if they are say more than an hour old. Depends on you application.

The point however is that if IM is left to run to completion then it should not leave tehse files. Do you have a timeout for the web application whcih may be the culprit?

prehaps each web job should use a different temp, and that whole directory can then be junked when that request is fiished.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
swiss_knife

Re: tons of magick-XXXX files in C:\Documents and Settings

Post by swiss_knife »

Actually my app is not a web app. My stuff is getting called from another application that can signal me for termination or just fill my process.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: tons of magick-XXXX files in C:\Documents and Settings

Post by anthony »

It is those signals that are causing you problems. You may be able to wrap the IM call in something to pass on the signal, wait, then cleanup, when it sees a signal.

This will work for any signal but signal 9 (unstoppable), and can be a simple shell script that also sets the MAGICK_TMPDIR environment vaibale to a directory the script can just recursivally delete when IM finishes or a terminate is passed on.

You will however need a signals savy UNIX programmer for this.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
swiss_knife

Re: tons of magick-XXXX files in C:\Documents and Settings

Post by swiss_knife »

We did put a catch in for Windows for ctrl-C but apparently it does not work properly and we're waiting for a Windows-savvy developer to help us resolve this problem. We used to have a atexit() handler
Hey "magick",
if you could point me out exactly where this code is in Magick, I am willing to have a look at this CTRL C handler and this atexit() function. Thank you.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: tons of magick-XXXX files in C:\Documents and Settings

Post by magick »

Take a look at NTControlHandler() in magick/nt-base.c. We currently do not call it but we can restore the call if you get it to work properly.
ptast

Re: tons of magick-XXXX files in C:\Documents and Settings

Post by ptast »

Magick,

Could it be possible to save the temporary data to eg C:\Documents and Settings\myname\Local Settings\Temp\ImageMagic and at startup delete all files and this would make it possible also for the calling (linked to IM) application to remove them?

I just noted that I had five 2gb (10gb of junk) magick-.... files in my temp directory....
wogabog

Re: tons of magick-XXXX files in C:\Documents and Settings

Post by wogabog »

Someone should take the time to look at & fix this issue in Windows, I just cleaned up over 300GB of magick-XXXX files in my user "Local Settings\temp" directory, some of them up to 80GB each!

It's not pleasant to find Imagemagick using up ~50% of my disk space. :shock:
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: tons of magick-XXXX files in C:\Documents and Settings

Post by magick »

We can only fix problems that we can reproduce. Post a command line or code snippets that leaves magick-* temporary files after the process finishes. If a temporary file remains it is a bug known as a file leak. Hopefully we will be able to reproduce the problem and we will fix the file leak within a day or two. As of today, with the current ImageMagick release (6.5.4-10), there are no known file leaks.

As previously mentioned, like most programs, ImageMagick cannot clean-up temporary files if it is interrupted and does not exit gracefully. We can catch some soft signals but certain signals such as SIGKILL does not provide an opportunity for ImageMagick to clean-up and exit gracefully. Under these circumstances, you must manually remove any temporary files.
Post Reply