Memory leak with OrderedDither on user-defined threshold
Posted: 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:
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:
This problem might show up with other version of perlmagick.
P.S.: The provided void-and-cluster dither matrix gives nice result
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
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");
}
P.S.: The provided void-and-cluster dither matrix gives nice result