Destructor (computer science) |
In object-oriented programming, a destructor is a method (computer science) which is automatically invoked when the object (computer science) is destroyed. Its main purpose is to clean up and to free the resource which were acquired by the object along its life cycle and unlink it from other objects or resources. The use of destructors is key to the concept of Resource Acquisition Is Initialization.
In a language with a automatic garbage collection mechanism, it is impossible to deterministically ensure the invocation of a destructor, and hence these languages are unsuitable for Resource Acquisition Is Initialization. In such languages, unlinking an object from existing resources should be done by an explicit call of appropriate function (usually called Dispose). This method is also recommended for freeing resources rather than using Finalizers for that.
=See also=
*Finalizer *Constructor (computer science) *Object lifetime *Resource Acquisition Is Initialization
=References=
|
|