When you declare an object using the constructor, you now have a variable name as a pointer to the object data in in memory. When you call delete() on an object, this calls the destructor. The effect of this is to remove the data pointed to by the variable name, invalidating the pointer.

In plain English, you should have one call to "delete" for every "new" used in object creation, and after you call delete, you can't access that object again.


In this diagram, each box is some memory block, containing some data. The variable name in the first box points to the object in the second box. The 0x0001 is just an arbitrary memory address.
<pre style="line-height: 8px;">joe = new Person("Joe", "Bloggs");
causes:
________ <u>0x0001 </u>
| joe: | | firstname: "Joe" | Memory taken off of the "safe to use" pile and
| 0x0001 | ==> | surname: "Bloggs" | Joe's data stored in it.
|________| |____________________|



delete joe;
causes:
________ <u>0x0001 </u>
| joe: | | Previous memory | Memory gets returned to the "safe to use" pile
| 0x0001 | ==> | of joe but memory | and other objects may now occupy it. For this reason,
|________| | is now available | referring to an object after it's been deleted could
| to other objects | mean you're referring to some other object unknowingly
|____________________| and is therefore unsafe.
</pre>