in reply to Re^2: private recursive subroutines
in thread private recursive subroutines

Btw, diotalevi also claimed that this memory leak issue is described somewhere in Higher Order Perl, but I couldn't find it in that book. I'd be greatful if anyone can point me to the exact place.

No. MJD ignored the problem and hoped p5p would solve it. That's not entirely unreasonable since this usage is common but it doesn't seem like its fix is immanent.

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Replies are listed 'Best First'.
Re^4: private recursive subroutines
by ambrus (Abbot) on May 13, 2007 at 09:04 UTC

    That's wierd, because I thought there was no way to fix this bug without a different garbage collector.

    On the other hand, I hope that the my $x; sub { sub { $x } } bug will be fixed by p5p, though I know nothing of its technical details.

      I think the hope was that my $x; $x = sub { $x } would be special-cased.

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

        I started to look into doing this (adding the special case if refcnt is 2 and the sv is an rv to a cv that closes over the sv to the "/* Can clear pad variable in place? */" code in scope.c), but something seems awry with the refcnt:
        perl -wle'use Devel::Peek; { my $f; $f = sub { my $c = shift; print $c +; $f->($c-1) if $c }; Dump $f; $f->(3); Dump $f }'
        The refcnt is 2 in the first dump and 5 in the second. Why?