Memory leak with OrderedDither on user-defined threshold

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
Samuel DEVULDER
Posts: 3
Joined: 2015-09-19T15:09:49-07:00
Authentication code: 1151

Memory leak with OrderedDither on user-defined threshold

Post by Samuel DEVULDER » 2015-09-19T15:17:25-07:00

Hello!

While working with perlmagick under cygwin, I think I have found a memory leak when using OrderedDither on a user-defined threshold.

My version of (perl)Magick is:

Code: Select all

$ convert -version
Version: ImageMagick 6.7.6-3 2012-04-28 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP
Here is a sample self-contained perl program showing the memory leak. Notice it define a temporary HOME to prevent destroying the real ~/.magick/threshold.xml but you can bypass this part as long as you use a user-defined threshold matrix. With built-in matrices the memory usage remain stable. With user-defined matrix like the one defined by the program, the memory use will grow until all memory is exhausted:

Code: Select all

#!/bin/perl

# use a temporary ~/.magick/threshold.xml (can be disabled)
if(1) { 
my($home) = "/tmp";
$ENV{'HOME'} = $home;
mkdir($home);
mkdir("$home/.magick");
open(THR, ">$home/.magick/thresholds.xml");
print THR <<EOF;
	  <thresholds>
		 <threshold map="sd">
			<description>void and cluster 65 niveaux</description>
			<levels width="8" height="8" divisor="65">
			   35 57 19 55 7 51 4 21
			   29 6 41 27 37 17 59 45
			   61 15 53 12 62 25 33 9
			   23 39 31 49 2 47 13 43
			   3 52 8 22 36 58 20 56
			   38 18 60 46 30 5 42 28
			   63 26 34 11 64 16 54 10
			   14 48 1 44 24 40 32 50
			</levels>
		 </threshold>
	  </thresholds>
EOF
close(THR);}
	  
# real code starts here:
use Image::Magick;
$img = Image::Magick->new(size=>"256x256", depth=>16);
$img->Read("logo:");
while(1) {
	# this one causes memory leak
	$img->OrderedDither(threshold=>"sd,2");
	# this one doesn't:
	#$img->OrderedDither(threshold=>"o4x4,2");
}
This problem might show up with other version of perlmagick.

P.S.: The provided void-and-cluster dither matrix gives nice result :)

User avatar
magick
Site Admin
Posts: 10980
Joined: 2003-05-31T11:32:55-07:00

Re: Memory leak with OrderedDither on user-defined threshold

Post by magick » 2015-09-20T03:50:26-07:00

We tried your script with recent versions of ImageMagick and cannot detect a leak. Consider upgrading your release of ImageMagick.

Samuel DEVULDER
Posts: 3
Joined: 2015-09-19T15:09:49-07:00
Authentication code: 1151

Re: Memory leak with OrderedDither on user-defined threshold

Post by Samuel DEVULDER » 2015-09-20T05:05:47-07:00

Thanks for your reply.

Ok, I'll try to upgrade, though upgrading perl-magick under cygwin has previously been a real pain because the newly installed version refuses to work for some obscure internal reasons[*]. Hopefully this is an old story, and latest version will work like a charm :)
___
[*] perl-module not found in the installation but being present on isk, or some dll couldn't be loaded because it's load address clashes with another dll in spite of rebaseall'ed everything.

Samuel DEVULDER
Posts: 3
Joined: 2015-09-19T15:09:49-07:00
Authentication code: 1151

[SOLVED] Re: Memory leak with OrderedDither on user-defined threshold

Post by Samuel DEVULDER » 2015-09-24T11:37:46-07:00

Ok, I checked with

Code: Select all

$ convert -version
Version: ImageMagick 6.9.1-3 Q16 i686 2015-07-01 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: DPC OpenMP
Delegates (built-in): autotrace bzlib cairo fftw fontconfig freetype fpx gslib jbig jng jpeg lcms lzma pangocairo png ps rsvg tiff webp x xml zlib
and the memory leak has gone. :)

Post Reply