Whenever a program creates garbage, the program is
said to have a memory leak.
If you wish to plug a memory leak caused by reassignment of a
pointer,
then instantiate one of the following patterns just before
the pointer is reassigned:
delete pointer to object;
delete [ ] pointer to array;
A destructor is a member function that is run when the memory
allocated for a class object is reclaimed.
Destructors frequently reclaim memory in excess of that
reserved for an object by applying the
delete operator to member variables that hold array pointers.
If a pointer is defined for a particular class,
and the pointer is assigned at run time to an object belonging
to a subclass of that defined class,
then indicate that the destructor is virtual.
As a rule, most destructors should be virtual destructors.
In contrast to ordinary member variables, there is only one chunk of
memory allocated for every member variable that you define to be static.
You can use static member variables to store properties of a class as a
whole.
If you want to define a member variable to be static,
then add the symbol static to that variables declaration.