PerlMagick runs out of 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
dlink

PerlMagick runs out of memory

Post by dlink »

Hi

We are using Perlmagick (Image::Magick) 6.0 for some time. We upgraded to 6.3.3 (CentOS, with 1GB of memory) and now the same program runs at of memory converting a 12Mb single page PDF file to a JPEG file.

While it use to die and report 'Endless loop' and 'Out of Memory', it might have been because we did not update Perlmagick but only Imagemagick. I since removed all 6.0 rpms, and reinstalled Imagemagick and perlmagick from source. Now it kswapd0 continually but does not compete or die.

Thank you for your help.

Here's the program:

Code: Select all

#!/usr/bin/perl -w                                                                
# $Id: myconvert.pl 26 2007-04-16 20:25:17Z dlink $                               

# This program behaves like a wrapper to ImageMagick's convert                    
# command line program.  It allows us to: crop, rotate, and resize                
# in that order, while the command line does not.                                 

use strict;
use Image::Magick;

# inputs:                                                                         

my ($crop, $rotation, $width, $input, $output) = @ARGV;
print "$crop, $rotation, $width, $input, $output\n" if $DEBUG;
die "myconvert.pl: incorrect number of arguments.\n" if $#ARGV != 4;

# Processing:                                                                     

my $image = Image::Magick->new;

# Read                                                                            
my $rc = $image->Read($input);
die $rc if "$rc";

# Crop                                                                            
$rc = $image->Crop(geometry => $crop);
die $rc if $rc;

# Rotate                                                                          
if ($rotation) {
    $rc = $image->Rotate($rotation);
    die $rc if $rc;
}

# Resize                                                                          
$rc = $image->Resize($width);
die $rc if $rc;

# Write out                                                                       
$rc = $image->Write($output);
die $rc if $rc;
User avatar
mi
Posts: 123
Joined: 2005-01-25T14:14:43-07:00
Contact:

Re: PerlMagick runs out of memory

Post by mi »

Yes, I'm seeing the same problem when running `make check' in the freshly built directory (6.3.5-3). The t/blob.t test, for example, reached the following record in top:

Code: Select all

  PID USERNAME    THR PRI NICE   SIZE    RES STATE  C   TIME   WCPU COMMAND
95869 mi            1 -20    0  5351M   711M swread 2   1:59  6.40% perl
and eventually died from memory exhaustion. My machine has "only" 2Gb of RAM and 4Gb of swap...
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: PerlMagick runs out of memory

Post by magick »

We have not heard this problem report before and unfortunately we currently cannot reproduce the problem. The posted PerlMagick script works fine for us in just a few megabytes of memory.
dlink

Re: PerlMagick runs out of memory

Post by dlink »

Here is the error message:

/plant/myconvert.pl 798x618+0+28 0 800
/data/stage_book_archive/2007-07-20/900100/900100.pdf
/mypublisher/tmp/900100/output.jpg: Cant load
/usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/auto/Image/Magick
/Magick.so
for module Image::Magick: libMagick.so.10: cannot open shared object
file: No such file or directory at
/usr/lib/perl5/5.8.8/i386-linux-thread-multi/DynaLoader.pm line 230. -
at /plant/myconvert.pl line 18 - Compilation failed in require at
/plant/myconvert.pl line 18. - BEGIN failed--compilation aborted at
/plant/myconvert.pl line 18. - Deep recursion on subroutine
"Image::Magick::AUTOLOAD" at
/usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/Image/Magick.pm
line 42. - Out of memory!
User avatar
mi
Posts: 123
Joined: 2005-01-25T14:14:43-07:00
Contact:

Re: PerlMagick runs out of memory

Post by mi »

I've seen this problem before (on FreeBSD), and -- contrary to assertions by "magick" -- it was reported on this very forum by myself and others.

It stems from PerlMagick being unable to load libMagick.so:
dlink wrote: for module Image::Magick: libMagick.so.10: cannot open shared object
file: No such file or directory at
/usr/lib/perl5/5.8.8/i386-linux-thread-multi/DynaLoader.pm line 230. -
Somehow this fairly trivial problem leads to a "cascading failure" leading to perl consuming all available memory before dying. I'm not sure, whether this is a bug in PerlMagick or in perl -- someone, who is good with the language, will need to investigate.

Once you figure this out -- by setting LD_LIBRARY_PATH to include the location of libMagick.so.10 or whatever else it takes on your OS -- the "runs out of memory" issue will go away too.
Post Reply