Subject: | memory leak in indexes() [XS] |
Date: | Sun, 07 Dec 2008 09:38:55 +1100 |
To: | bug-List-MoreUtils [...] rt.cpan.org |
From: | Kevin Ryde <user42 [...] zip.com.au> |
With the debian packaged MoreUtils 0.22 and perl 5.10.0 the memory used
by the program below grows apparently forever.
If the two lines at the start are uncommented to use the pure-perl
MoreUtils there's no memory growth. I suspect the ref count on the
return values from List::MoreUtils::indexes() may be keeping them alive
forever.
(Incidentally, I saw the comments in MoreUtils.xs firstval() and
lastval() referring to doing the same inc as in indexes(), but I believe
those former two don't leak, as far as I can see. I guess the typemap
for an SV* return does an sv_2mortal on it. I don't think the same on
the multiple returns from indexes() would be enough though, since an
error throw in the callback would still leak the returns built up but
not yet mortalized.)
use strict;
use warnings;
# use Carp;
# BEGIN { $ENV{LIST_MOREUTILS_PP} = 1; };
use List::MoreUtils;
my @a = (10,11,12,13,14,15);
print "odd numbers: ", (List::MoreUtils::indexes {$_&1} @a), "\n";
for (;;) {
List::MoreUtils::indexes {$_&1} @a;
}