You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Jon Molin <Jo...@resfeber.se> on 2001/08/21 11:14:46 UTC

perlmagick and leaking memory

Hi list,

I've done a scripts that builds an calender and colours the days with
different colours depending on the status of the day. I've got 6 colours
and one to just fill out so the month starts with the correct day, ie
i've got 6 * 31 + 1 = 187 images and each is about 70 bytes so a
calender is 6 times 7 of these little sqaures, about 3k. 

Now this little script handling this tiny amount of data runs amok and
grows and grows untill i restart apache brutaly, I guess I've done
something very wrong but I can't figure out what, nor can I find any
info about this. Here's what the program looks like:


my $image_obj = Image::Magick->new;
my $images = $image_obj->Read (@days); # an array with 49 filnames
my $montage = $image_obj->Montage (
                                   mode => 'Concatenate',
                                   background =>'#ffffff',
                                   tile => '7x7',
                                   frame => '1x1',
				   gravity => 'center',
                                   );

$montage->Crop ('138x118'); #fixing the size

print "Content-Type: image/gif\n\n" ;
$montage->Write();# the image doesn't come out out unless i use Write
before
print $montage->ImageToBlob();

undef $montage;
undef $images;
undef $image_obj;


Anyone see any obvious mistakes?

I also tried putting this before the undef's but it didn't do any
difference:
for (my $i = 0; $i <= 48; $i++)
{
    undef $image_obj->[$i];
}

/Jon

Re: perlmagick and leaking memory

Posted by Joshua Chamas <jo...@chamas.com>.
Jon Molin wrote:
> 
> Hi list,
> 
> I've done a scripts that builds an calender and colours the days with
> different colours depending on the status of the day. I've got 6 colours
> and one to just fill out so the month starts with the correct day, ie
> i've got 6 * 31 + 1 = 187 images and each is about 70 bytes so a
> calender is 6 times 7 of these little sqaures, about 3k.
> 
> Now this little script handling this tiny amount of data runs amok and
> grows and grows untill i restart apache brutaly, I guess I've done
> something very wrong but I can't figure out what, nor can I find any
> info about this. Here's what the program looks like:
> 

Generally, I am not surprised when finding memory leaks in XYZ
module.  The code in the email looked fine, so I would suspect
Image::Magick having the leak.  To prove this better, you might
take the code out of the mod_perl request, and run it through a 
test of 1000 iterations in a command line script, and report the 
problem to the author of Image::Magick.

So, without waiting for a Image::Magick fix, you can make
memory leaks less painful by setting MaxRequestPerChild lower, say
to 100 or by using a solution like Apache::SizeLimit to kill a child 
process when it uses too much RAM ( unshared RAM on Linux too )

--Josh

_________________________________________________________________
Joshua Chamas                           Chamas Enterprises Inc.
NodeWorks Founder                       Huntington Beach, CA  USA 
http://www.nodeworks.com                1-714-625-4051