Thursday, June 21, 2012

Perl - Garbage collection and Destructors

Automatic reclamation process is known as Garbage collection. Perl uses a fast and simple reference-based garbage collector. It does this automatically for you as soon as object goes out of scope.

You may want to provide your own destruction mechanism. For that you may need to define a special method called Destroy. This method will be called on the object just before Perl frees memory allocated to it.

A Destroy method is absolutely essemtial in the situations in which you have objects that refer to nested structures. Perl also uses only one Destroy method per object destroyed regardless of inheritance. If your class overrides a superclass's destructor, then your Destroy method may need to invoke the Destroy method for any applicable base classes

No comments:

Post a Comment