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
From:
Dave Mitchell
Date:
August 1, 2013 01:08
Subject:
Re: [perl #119049] referencing some variables hides others fromPadWalker starting 5.17.2
Message ID:
20130801010805.GY2177@iabyn.com
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 Foo.pm 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.


-- 
print+qq&$}$"$/$s$,$a$d$g$s$@$.$q$,$:$.$q$^$,$@$a$~$;$.$q$m&if+map{m,^\d{0\,},,${$::{$'}}=chr($"+=$&||1)}q&10m22,42}6:17a2~2.3@3;^2dg3q/s"&=~m*\d\*.*g

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About