In object-oriented programming, a destructor is a method which is automatically invoked when the object is destroyed. Its main purpose is to clean up and to free the resources which were acquired by the object along its life cycle and unlink it from other objects or resources invalidating any references in the process. The use of destructors is key to the concept of RAII. A destructor that returns a value can be used to obtain a representation of an object of a class.
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 RAII. 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.
Class Foobar // Old form Sub ~Foobar() End Sub // New form Sub Destructor() End Sub End Class
Destruktorius (programavimas) | Destruktor | Деструктор (программирование)
This article is licensed under the GNU Free Documentation License.
It uses material from the
"Destructor (computer science)".
Home Page • arts • business • computers • games • health • hospitals • home • kids & teens • news • physicians • recreation• reference • regional • science • shopping • society • sports • world