On Wed Jul 31 16:51:01 2013, rjbs wrote: > On Wed Jul 31 16:35:13 2013, rjbs wrote: > > What are the practical wins to making closure per-variable instead of > > per-environment? > > Presumably the answer is equivalent to "closes #89544" Yes. But it can be phrased like this: It makes it easier to avoid memory leaks. Now one thing we could do is leave the closure with its CvOUTSIDE pointer but make it a weak pointer. That would involve backreferences to make sure it gets cleared if the outer sub is freed. I didn’t think it was worth the complexity involved. How strongly do you feel about having this work? BTW, PadWalker does give surprising results even before a0d2bbd5c47 if it accesses a variable implicitly closed over that comes from an outer scope that is not a closure, and that outer scope has already exited. $\="\n"; use PadWalker peek_my; sub outer { my $x = 2; my $sub = sub { ${ peek_my(0)->{'$x'} } }; print "Before scope exit: ", $sub->(); $sub; } print "After scope exit: ", outer->(); __END__ Before scope exit: 2 After scope exit: That we cannot fix without introducing potential memory leaks in places where 5.16 didn’t have them. In this case, and in the original report, explicitly naming the variable in the anonymous subroutine will cause the second line to print 2 as well. Is it worth trying to fix this if we cannot get it to work completely? -- Father Chrysostomos --- via perlbug: queue: perl5 status: rejected https://rt.perl.org:443/rt3/Ticket/Display.html?id=119049Thread Previous | Thread Next