develooper Front page | perl.perl5.porters | Postings from June 2009

Re: DESTROY: is there any predictability about when it's called?

Thread Previous
From:
Andy Armstrong
Date:
June 13, 2009 11:27
Subject:
Re: DESTROY: is there any predictability about when it's called?
Message ID:
359CDB1A-6153-450E-AE17-8236D672C4EC@hexten.net
On 13 Jun 2009, at 17:50, Vincent Pit wrote:
>> it seems that $state is DESTROYed /before/ $foo - which surprises  
>> me a
>> little. And, as I said, it doesn't seem to help if I wrap the closure
>> call in nested blocks or even an additional layer of sub call.
> I think $foo is destroyed when $block's pad is freed, which happens  
> when
> $block goes out of scope.

Ah! That might help, thanks.

>
>> From your code, I'd expect it to happen after $state is destroyed.
> Try to move the $state declaration before the block one. Another  
> idea is
> to store a reference to $state inside the block you call :
>
>  my $rc = sub { my $dummy = $state; goto &$block }->();


So might that :)

-- 
Andy Armstrong, Hexten


Thread Previous


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