ReadImage constitue.c consumes memory

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
udayakumar

ReadImage constitue.c consumes memory

Post by udayakumar »

thought I should submit here for anyone authored the ReadImage function in constitute.c.

I tested 32 page TIFF file. This is merely a 2.8Mb in disk. To experiment I just called the ReadImages() in MagickNet and the memory consumed after loading was 1.6Gb.

my sample code is;

string file = "c:\temp\abc.tiff";
ImageMagickNET.ImageList imlist = new ImageMagickNET.ImageList();
imlist.ReadImages(file);

Message.Show("pause here to check the taskmanager memory usage");

When I check the memory in the task manager the cosumed memory is about 1.6Gb.
It does not look like an expected behaviour.

Anyone else experienced this behaviour? I am using ImageMagick 6.5 latest release.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: ReadImage constitue.c consumes memory

Post by magick »

High memory usage is expected. See http://www.imagemagick.org/script/architecture.php.
udayakumar

Re: ReadImage constitue.c consumes memory

Post by udayakumar »

I think this behaviour is not by design. When I say a file that is 2.8M to look 1.3G does not look normal.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: ReadImage constitue.c consumes memory

Post by magick »

It does not matter how well the image compresses on disk, the ImageMagick pixel cache is scaled by the image size and quantum depth. Assume you have 32 1024x1024 images and ImageMagick is Q16. Each pixel consumes 4 color components at 16-bits. So 32*1024*1024*8 is 1/4 GB. Now transform the image, let's say we resize it to double size. That's an addition 1/2GB of memory or disk resources. We're now at 3/4 GB. If your images are colormapped it requires an extra color channel and now you are consuming 1GB of memory. You can save half the memory requirement by installing the Q8 version of ImageMagick at 8-bits per pixel component. You can also create the pixel cache on disk rather than memory like this:
  • convert -limit area 1 image.tif image%d.jpg
udayakumar

Re: ReadImage constitue.c consumes memory

Post by udayakumar »

How do I create a pixel cache in the disk rather than memory. I am using the Imagemagick .net wrapper. Is there a C++ interface to specify the cache location?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: ReadImage constitue.c consumes memory

Post by magick »

You can force the pixel cache to disk with the MAGICK_AREA_LIMIT environment variable (see http://www.imagemagick.org/script/resou ... nvironment). Or set it as a matter of policy (see http://www.imagemagick.org/script/resou ... #configure). Or from the MagickCore API, use SetMagickResourceLimit(). Perhaps there is a similar method in MagickNet.
udayakumar

Re: ReadImage constitue.c consumes memory

Post by udayakumar »

Thanks much that helped somewhat to improve the system responsiveness of the other applications. But slows my applicaiton processing time.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: ReadImage constitue.c consumes memory

Post by magick »

A slow down is expected, disk is 1000 times slower than memory. However, it reduces memory usage by ImageMagick considerably. Its a trade-off.
Post Reply