previous | start | next

## Automatic Memory Management

- The destructor is automatically invoked (not called directly).

  >     {
  >        Department dept;
  >        ...
  >     } // dept.~Department() automatically invoked here

  >     ...
  >     Department* p = new Department(...);
  >     ...
  >     delete p; // p->~Department() automatically invoked here

- A class can only have one destructor with no parameters.
- You should always supply a destructor when some amount of clean up is required when an object goes out of scope.
  - Recycling dynamic memory (as shown here).
- - Close a file.
  - Relinquish some other resource.

previous | start | next