go ahead... be a heretic | |
PerlMonks |
Is assigning undef required for DESTROY to run?by MidLifeXis (Monsignor) |
on Feb 23, 2009 at 19:52 UTC ( [id://745818]=perlquestion: print w/replies, xml ) | Need Help?? |
MidLifeXis has asked for the wisdom of the Perl Monks concerning the following question: I have a vendor's library, distributed in binary mode only. It seems that if I create an object using this library, I need to assign undef to get it to call the DESTROY method. If I assign a new invocation of the item to the object variable, it core dumps. This core dumps...
This does not...
I am probably assuming too much out of this vendor, but shouldn't the two snippets of code be expected to do the same thing, or are my expectations out of whack? I will be submitting the bug in any case (I should not be able to force the library to core dump, IMO), but am evaluating my expectations. ------ After further research, I think I may have an explanation. In Conway's OOP, on page 430, it states: A destructor is a method with the special name of DESTROY. It is called automatically when an object's reference count reaches zero. In the first instance, the creation of the second object happens before the first object's refcount reaches 0, as the assignment happens after the new call. In the second instance, the assignment of undef causes the refcount to drop to 0, then the creation of the new object is possible to happen, then the assignment happens. I know that I answered this myself. Documenting this here, with more information, may help another monk in the future. --MidLifeXis
Back to
Seekers of Perl Wisdom
|
|