A special class method called when an object instance of a class is destroyed. With some languages they are called when the object instance goes out of scope, with some languages you specifically have to call the destructor in code to destroy the object, and others use a garbage collector to dispose of object instances at specific times.
Desctructors are commonly used to free the object instance but with languages that have a garbage collector object instances are disposed of when appropriate. Either way, destructors or their equivalent are commonly used to free up resources allocated in the class constructor.
Languages Focus: Destructor
Are object instances freed with a garbage collector? Or, do you have to destroy object instances.
C++ Destructor
A member function with the same name as the class prefixed with a ~ (tilde). C++ destructors are automatically called when an object goes out of scope, or when you delete a dynamically allocated object. Every class can have only one destructor.
Syntax Example: class Cyborg {
public:
// Constructor for class Cyborg
Cyborg();
// Destructor for class Cyborg
~Cyborg();
};