Originally Posted by
Elysia
Let 's put it this way...
When you use new, you are creating a new house out there in the wide world, somewhere.
New then returns the address where that house is located.
If you assign ptr1 to ptr2, then ptr2 also holds the address where the house is located.
When you call delete, the bulldozer drives to the address in the pointer you give it and demolishes the house.
So if you call delete on ptr1, then what happens to ptr2? Easy. Ptr2 just holds the address of the (now) demolished house! So ptr2 (as well as ptr1) is now invalid.
If you call delete on ptr2 after ptr1 now, the bulldozer will try to demolish an already demolished house (which, in the computer world, is a big no-no).
If you set the pointer to 0 before calling delete, the bulldozer can't find the house anymore. Its address is lost and you get a memory leak.
The concept is that pointers contains the address and no the house (object) itself.