in reply to Re: Garbage-collecting with closures
in thread Garbage-collecting with closures

It does not leaks memory for me. Why should it?

I tried

my $foo; sub leaky { my $closure = sub { $foo++ }; } for (;;) {leaky}
for quite a long time and saw usage of constant memory.

Courage, the Cowardly Dog

Replies are listed 'Best First'.
Re: Re: Re: Garbage-collecting with closures
by perrin (Chancellor) on Feb 20, 2003 at 15:02 UTC
    Sorry, my mistake. They have to be nested anonymous subs, like this:
    my $foo = 'asdf' x 1000; for (1..900000) { my $outer_sub = sub { my $inner_sub = sub { $foo }; } }
      You're right.

      I think this code should be fed to 'perlbug' utility.

      Although I seem to remember it was discussed in p5p list somehow, such closure leaks were almost went away just before 5.6.0, but they were too evil to fix.

      Courage, the Cowardly Dog