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...
my $obj = Vendor::Library->new(...); ... code here ... $obj = Vendor::Library->new(...);
This does not...
my $obj = Vendor::Library->new(...); ... code here ... $obj = undef; $obj = Vendor::Library->new(...);
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Is assigning undef required for DESTROY to run?
by Corion (Patriarch) on Feb 23, 2009 at 19:59 UTC | |
|
Re: Is assigning undef required for DESTROY to run?
by kennethk (Abbot) on Feb 23, 2009 at 20:06 UTC | |
by MidLifeXis (Monsignor) on Feb 23, 2009 at 20:17 UTC | |
by Bloodnok (Vicar) on Feb 24, 2009 at 09:12 UTC | |
|
Re: Is assigning undef required for DESTROY to run?
by Tanktalus (Canon) on Feb 24, 2009 at 01:04 UTC | |
by MidLifeXis (Monsignor) on Feb 24, 2009 at 11:33 UTC | |
|
Re: Is assigning undef required for DESTROY to run?
by CountZero (Bishop) on Feb 23, 2009 at 22:42 UTC | |
by MidLifeXis (Monsignor) on Feb 23, 2009 at 22:48 UTC |