I've identified what seems to be a memory leak in Perl and verified it on 5.8.0 on a Windows machine and 5.005_03 on a UNIX server. It seems to occur when an anonymous subroutine is defined with code that would cause recursion. The simplified example below demonstrates the problem. Try running it on your system with Task Manager or `top` running to see the memory usage climb. On my system it gobbles up about 100MB per second for the first 3 seconds. Note that &$sub_ref() is never actually called: the recursion is defined but never executed.
use strict; # leak occurs whether strict is used or not
while(1) {
&leak();
}
sub leak {
my $sub_ref;
$sub_ref = sub { &$sub_ref(); };
return 0;
}
To provide context, a more realistic usage might involve computing a factorial.
sub leak {
my $factorial_sub_ref;
$factorial_sub_ref = sub {
my ($number) = @_;
if ($number < 2) { return 1; }
return($number + &$factorial_sub_ref($number - 1));
};
return 0;
}
Additional context: this problem originally occured for me in a recursive descent parser, which had a whole lot of tiny functions I wanted to obscure from UltraEdit's function list.
Is this a Perl bug? If so, where can I find more information about its status?