in reply to Writing a REAL destructor
The DESTROY method is special because perl calls it when it realizes it can garbage-collect the object in question. If you would like to manually release the object from memory (by the way, do you have a good reason for this?), you should not call DESTOY directly, which, as you noted, will simply cause it to be called twice. Instead, you delete the last reference to the object, eg:
Immediately after the undef(), the object will be freed (because Perl uses a ref-counting GC) and DESTROY called.my $me = new Person; $me->name("Andy"); undef $me;
ps. My condolences regarding Andy.
MeowChow s aamecha.s a..a\u$&owag.print
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: (MeowChow) Re: Writing a REAL destructor
by Dog and Pony (Priest) on Jun 05, 2002 at 08:34 UTC | |
by Aristotle (Chancellor) on Jun 05, 2002 at 09:07 UTC | |
by Abigail-II (Bishop) on Jun 05, 2002 at 14:58 UTC | |
by Aristotle (Chancellor) on Jun 05, 2002 at 16:35 UTC | |
by Abigail-II (Bishop) on Jun 05, 2002 at 17:28 UTC | |
| |
by MeowChow (Vicar) on Jun 05, 2002 at 08:47 UTC | |
Re: (MeowChow) Re: Writing a REAL destructor
by NaSe77 (Monk) on Jun 05, 2002 at 09:10 UTC | |
by Abigail-II (Bishop) on Jun 05, 2002 at 15:03 UTC |
In Section
Seekers of Perl Wisdom