sub foo
{
my $val;
if( @_ ) {
$val= shift;
} else {
undef $val;
}
return $val;
}
foo( "x" x 10_000 );
# 10,000 bytes of memory still tied up
foo()
# those 10,000 bytes now free to be reused
foo( \( "x" x 10_000 ) );
# the few bytes needed to store a reference still tied up,
# but the 10,000 bytes for the string value itself are
# already free to be reused.
Yes, closures never being freed is a bug due to Perl itself
making a circular reference. I believe this has already
been fixed. Your example code should not leak memory
whether you consider it reasonable for that to happen
or not. (:
-
tye
(but my friends call me "Tye") |