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.
Wilbert
Post
by Wilbert » 2009-10-10T14:57:57-07:00
I'm using 6.5.6-9 and the MagickCore api. It seems that the memory is not being released after reading one image. I used the following code:
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <magick/MagickCore.h>
#include <windows.h>
void main(int argc, char *argv[])
{
ExceptionInfo *exception;
Image *image, *images, *resize_image;
ImageInfo *image_info;
char BUF[256];
int j;
for (j=1; j<65; j++) {
sprintf(BUF, "001-%03d.jpg", j);
OutputDebugString(BUF);
MagickCoreGenesis(argv[1], MagickTrue);
image_info = CloneImageInfo((ImageInfo *) NULL);
exception = AcquireExceptionInfo();
(void) strcpy(image_info->filename, BUF);
images = ReadImage(image_info, exception);
images = CoalesceImages(images, exception);
image = GetImageFromList(images, 0);
resize_image = ResizeImage(image,640,480,LanczosFilter,1.0,exception);
// Write the image thumbnail
(void) strcpy(resize_image->filename, "thumbnail.JPG");
WriteImage(image_info, resize_image);
DestroyImage(image);
DestroyImage(resize_image);
DestroyImageInfo(image_info);
DestroyExceptionInfo(exception);
MagickCoreTerminus();
}
}
When running the executable the memory usage keeps growing and growing until all the images (size: ~3000x2000) are processed. After processing 50 images the mem usage is already at 1.750.000. It drops back to 486.000 when the program is ready. It this a bug, or should i change the code?
magick
Site Admin
Posts: 11064 Joined: 2003-05-31T11:32:55-07:00
Post
by magick » 2009-10-10T15:18:09-07:00
You have a leak here:
images = ReadImage(image_info, exception);
images = CoalesceImages(images, exception);
You also need to take MagickCoreGenesis() and MagickCoreTerminus() methods outside the loop.
Wilbert
Post
by Wilbert » 2009-10-10T15:28:56-07:00
Thanks for the fast response!
You also need to take MagickCoreGenesis() and MagickCoreTerminus() methods outside the loop.
Ok.
You have a leak here:
images = ReadImage(image_info, exception);
images = CoalesceImages(images, exception);
So, how should i change my code? If i change it as follows:
Code: Select all
Image *image, *images, *images2, *resize_image;
// ...
images = ReadImage(image_info, exception);
images2 = CoalesceImages(images, exception);
the same problem remains.
magick
Site Admin
Posts: 11064 Joined: 2003-05-31T11:32:55-07:00
Post
by magick » 2009-10-10T15:31:06-07:00
Every image created must be destroyed. Use DestroyImageList(images).
Wilbert
Post
by Wilbert » 2009-10-10T15:38:11-07:00
If i do that, my program crashes:
Code: Select all
//..
MagickCoreGenesis(argv[1], MagickTrue);
for (j=1; j<65; j++) {
sprintf(BUF, "001-%03d.jpg", j);
OutputDebugString(BUF);
image_info = CloneImageInfo((ImageInfo *) NULL);
exception = AcquireExceptionInfo();
(void) strcpy(image_info->filename, BUF);
images = ReadImage(image_info, exception);
images2 = CoalesceImages(images, exception);
image = GetImageFromList(images2, 0);
resize_image = ResizeImage(image,640,480,LanczosFilter,1.0,exception);
// Write the image thumbnail
(void) strcpy(resize_image->filename, "thumbnail.JPG");
WriteImage(image_info, resize_image);
DestroyImage(image);
DestroyImage(resize_image);
DestroyImageList(images);
DestroyImageList(images2);
DestroyImageInfo(image_info);
DestroyExceptionInfo(exception);
}
MagickCoreTerminus();
Something about the 'memory couldn't be read'.
Wilbert
Post
by Wilbert » 2009-10-10T15:41:29-07:00
Hmm, if i remove the DestroyImage(image); line everything works fine!!!
Is image automatically destroyed when images2 is destroyed?
magick
Site Admin
Posts: 11064 Joined: 2003-05-31T11:32:55-07:00
Post
by magick » 2009-10-10T15:50:22-07:00
You destroy image and images2 which are aliased to each other so you are destroying the same image memory twice which is a bad-bad thing.
Users browsing this forum: No registered users and 6 guests