called automatically when the object goes out of scope. Because C++ does not have garbage collection, if the object was created with a statement (dynamically on the heap), then its destructor is called when the operator is applied to a pointer to the object. Usually that operation occurs within another destructor, typically the destructor of a smart pointer object. In inheritance hierarchies, the declaration of a virtual destructor in the base class ensures that the destructors of derived classes are invoked properly when an object is deleted through a pointer-to-base-class. Objects that may be deleted in this way need to inherit a virtual destructor. A destructor should never throw an exception. Non-class scalar types have what's called a which can be accessed by using typedef or template arguments. This construct makes it possible to write code without having to know if a destructor exists for a given type. int f() { int a = 123; using T = int; a.~T(); return a; // undefined behavior } In older versions of the standard, pseudo-destructors were specified to have no effect, however that was changed in a defect report to make them end the lifetime of the object they are called on. Example #include <cstring> #include <iostream> class Foo { public: Foo(): data_(new char[sizeof("Hello, World!")]) { std::strcpy(data_, "Hello, World!"); } Foo(const Foo& other) = delete; // disable copy construction Foo& operator=(const Foo& other) = delete; // disable assignment ~Foo(void) { delete[] data_; } private: friend std::ostream& operator<<(std::ostream& os, const Foo& foo) { os << foo.data_; return os; } char* data_; }; int main() { Foo foo; std::cout << foo << std::endl; } Objects which cannot be safely copied and/or assigned should be disabled from such semantics by declaring their corresponding functions as deleted within a public encapsulation level. A detailed description of this method can be found in Scott Meyers' popular book, Effective Modern C++ (Item 11: "Prefer deleted functions to private undefined ones."). In C with GCC extensions The GNU Compiler Collection's C compiler comes with 2 extensions that allow implementing destructors: The destructor function attribute allows defining global prioritized destructor functions: when main() returns, these functions are called in priority order before the process terminates. See also: Hacking the art of exploitation. The cleanup variable attribute allows attaching a destructor function to a variable: the function is called when the variable goes out of scope. Xojo Destructors in Xojo (REALbasic)