in reply to Re: Acky Memory
in thread Acky Memory
When Perl sees that an object is no longer being used by anyone, it will reclaim the memory for the object automatically. Just before it does this, it will call the DESTROY method automatically, to perform any final cleanup that the object requires, such as closing any filehandles that it might contain.
If you call DESTROY yourself, you will have an object in an inconsistent state, because DESTROY thought that the object was about to be destroyed. But it was not destroyed, because some part of the program still has a reference to it; you called DESTROY permaturely. And then later, when Perl sees that the object is no longer useful, it will reclaim the memory for the object and call DESTROY a second time. This could easily cause all sorts of havoc because a DESTROY method is only supposed to be called once.
Finally, you run the risk of a fatal run time error because not every object has a DESTROY method, and if you call the DESTROY method on an object that doesn't have one, your program will die.
Summary: never call $o->DESTROY.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: Acky Memory
by mirod (Canon) on Nov 12, 2000 at 19:35 UTC |