|Keep It Simple, Stupid|
Re^2: sub DESTROY: Strange ordering of object destructionby ELISHEVA (Prior)
|on Mar 03, 2011 at 11:45 UTC||Need Help??|
ikegami - you are spot on here. To get a better understanding of the actual timing of the call to DESTROY, I used your suggestion (in the cb) of adding the following END block:
Sure enough, the destruction is happening during global destruction, despite the undef $A much earlier. As clarified in the CB, during global destruction objects are destroyed in any order, so one should never assume that just because A holds a reference to B that A a will be destroyed before B.
To be honest, this still surprises me. Once I called undef $A there were no more variables storing a reference to A. i.e. the code was essentially nothing more than
Wouldn't that undef result in the reference count for whatever was created by SomeClass->new going down to 0? If not, why not? There are no circular refrences in SomeClass - it stores only a reference to B and some pure scalars (strings, numbers). B is a third party class that has no knowledge of A and no way to pass in a reference to A, so a circular reference A->B->A isn't possible.
If yes, in the CB you said that destruction happens as soon as the reference count goes to 0. However, destruction is still happening only after the END block executes. Why?
In any case, thanks, again, for the END block suggestion in the CB.
Update: added comment about circular references.