Automatic default destructor
- An automatic default destructor is added to your class if no other destructor is defined.
- The only action of the automatic default destructor is to call the default destructor of all member objects.
- A destructor should never be called directly. Instead, it is automatically called when the object’s memory is being reclaimed by the system
- if the object is on the stack, when the function returns
- if the object is on the heap, when delete is used
Custom destructor
A custom destructor is essential when an object allocates an external resource that must be closed or freed when the object is desteroyed.
Examples:
- Heap memory
- Open files
- Shared memory