Hi,
> >> With this simple test script:
> >>
> >> print "Content-type: text/html\n\n";
> >> my $var = 'x' x 500000;
> >
> > our $var = 'x' x 500000;
> >
> >>
> >> my $sub = sub { my $sub2 = sub { $var; }; };
> >> print "Done\n";
> >>
> >> $var does not get freed, and the process grows each request. Has anyone
> >> seen this sort of behavior and have any ideas/workarounds (besides don't
> >
> > yes. this is the documented behavior for closures. the anonymous sub
> > must have it's own copy of $var which happens to be 500k plus perl
> > overhead on each invocation.
>
> I think the problem is that $var doesn't get freed even when $var and
> $sub and $sub2 have all gone out of scope. That's a perl bug for which I
> can fathom no workaround.
>
> If any of those variables are still in scope, then of course $var can't
> get freed.
Yes, upon further investigation, this perl script:
while (1) {
{
my $var = 'x' x 500000;
my $sub = sub { my $sub2 = sub { $var; } };
}
# $var and $sub should be gone, but memory is never freed
sleep 1; # Don't crash things =)
}
will grow forever as $var never seems to be freed even when everything
should go out of scope, definately a perl bug, not a mod_perl one. =)
Oddly, if you just do
my $sub = sub { $var; };
it does not grow, definately something strange going on. Happens on
perl 5.004_04, 5.005_03 and 5.6.1.
Cheers,
Alex