Lecture 4 - Slide 12 : 40
A class that needs a destructor

An example where it is necessary to program a destructor

For sake of the example we introduce a dynamically allocated representation of points

Class Point - representated as a dynamically allocated array of two doubles .
Implementation of class point - with an insufficient destructor .
A sample program with memory leaks.
Class Point - with a pointer representation - same as before.
Implementation of class point - now with a destructor that deallocates the Point representation.
A sample program - now without memory leaks.
Output from the program.
Go to exercise
Point destruction - now with a problematic point copy constructor

If an object o allocates resources when constructed - or during its life time - o's destructor is responsible for relinquishing these resources when o is deleted or goes out of scope

If o does not allocate such resources, its destructor is typcially not programmed