in reply to Re^4: when is destroy function called
in thread when is destroy function called
Hello roboticus,
Thanks for taking so much trouble in your explanation! I’ve been trying — with limited success :-( — to wrap my head around it for about a day now, which is why I haven’t replied sooner.
I’m confused by this:
Here, we’ve already executed the obey() method so the string gets printed, and we’ve just executed undef, so the link between $enemy and the Dalek is now broken. But the argument stack for print still holds the reference to the Dalek.
I would have expected that each argument is popped from the stack as it is processed, so that its reference count is decremented as it leaves the stack. But I admit I don’t really know how all this works.
Your use of Devel::Peek is interesting. (Incidentally, I think the expression ${shift}->{theVal} should be shift->{theVal}?) Looking at the reference counts, I can’t see the increment you predict between “before print” and “Do the print” — what should I be looking at?
I did find this in the section Reference Counts and Mortality in perlguts:
There are some convenience functions available that can help with the destruction of xVs. These functions introduce the concept of "mortality". An xV that is mortal has had its reference count marked to be decremented, but not actually decremented, until "a short time later". Generally the term "short time later" means a single Perl statement, such as a call to an XSUB function.
If that passage is relevant to the situation we’ve been discussing, it supports your idea that it is the decrementing of the reference count to zero which is delayed until the print statement completes, and that, when the reference count reaches zero, the destructor is called immediately.
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: when is destroy function called
by roboticus (Chancellor) on Mar 06, 2013 at 02:37 UTC | |
by Athanasius (Archbishop) on Mar 06, 2013 at 13:11 UTC | |
by roboticus (Chancellor) on Mar 06, 2013 at 17:19 UTC | |
by bulk88 (Priest) on Apr 21, 2013 at 03:48 UTC |