in reply to Re: Reference to guard not released
in thread Reference to guard not released
Well, it is more interesting to show when the closure stored in $code is effectively destroyed:
Output on perl 5.14.2:use strict; use Scope::Guard; my $x; my $code = do { my $g; sub { my $z; $g = Scope::Guard->new( sub { warn "destroyed"; $z } ); } }; use Scalar::Util (); Scalar::Util::weaken(my $code2 = $code); $code->(); printf "code2: %d\n", !!(defined $code2); undef $code; printf "code2: %d\n", !!(defined $code2); warn "end";
As shown above, the issue is independent of $x being global: here I'm using $z which is local to the enclosing closure and the behavior is the same: the closure pointed by $code is not freed.code2: 1 code2: 1 end at x.pl line 21. destroyed at x.pl line 10 during global destruction.
|
|---|