develooper Front page | perl.perl5.porters | Postings from August 2013

Re: [perl #119049] referencing some variables hides others fromPadWalker starting 5.17.2

Thread Previous | Thread Next
Dave Mitchell
August 1, 2013 01:08
Re: [perl #119049] referencing some variables hides others fromPadWalker starting 5.17.2
Message ID:
On Wed, Jul 31, 2013 at 04:35:14PM -0700, Ricardo SIGNES via RT wrote:
> What are the practical wins to making closure per-variable instead of per-environment?

Not having to field about 10 new bug reports per week about leaks???

e.g. if we changed it, then in

    sub gen {
	my ($a,$b,$c) = ... intermediate calculations ...;
	my $x = something;
	return sub { $x };

everyone would complain about how $a,$b,$c now leak.

And that's a simple case; as things get more complex, the
interrelationships between nested closures etc would mean nothing would
ever end up getting freed, with everything tied back in a chain to the
longest-lived element.

Also in a typical file like

    package Foo;
    my ($a, $b, $c);
    Sub f1 { $a };
    ... more lexicals ...
    ... more subs ....
    ... and so on for several 100 lines ...
The subs would probably end up capturing every lexical declared within
Foo, which would probably continue to exist until global destruction.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About