Advertisement

Memory deallocation

Started by December 21, 1999 09:47 AM
0 comments, last by Gandalf 24 years, 11 months ago
I have a question about memory deallocation in a double linked lists. If I have a pointer to a list, lets call it pmonster, witch among other things contains a pointer to a surface, and I deallocate memory for the pointer. Now what happens to the surface pointer in the class? Should´nt I call Release() on that pointer before I deallocate pmonster, or is this done automaticly?

------------------
Gandalf the White

Gandalf the Black
When you free an object using delete it calls your destructor, does whatever the destructor tells it, then frees the memory of the object itself.
It won't check your object for pointers and auto free them (thank God) unless you explicitly tell it to in the destructor of the object your freeing.
So in the destructor you should put code to free all memory you want freeing with as much error checking as possible.

C/C++ is great because it gives you all the control in the world but it also expects you to do all the work. A fair trade off IMHO.

Mike

This topic is closed to new replies.

Advertisement