When a class object goes out of scope, a special function called the destructor gets executed. The destructor has the same name as the class tag but prefixed with a ~(tilde). Destructor function also return nothing and it does not associated with anydata type.
The purpose of the destructor is to free the resources that the object may have acquired during its lifetime. A destructor function removes the memory of an object which was allocated by the constructor at the time of creating a object.