C++ is not a garbage collected language. (1) If memory is allocated and deallocated the allocator can do what it wishes with the free memory. It is not required to, and in many cases will not, reduce the size of the heap as far as any monitoring tools can see and this does not mean there is a leak. The only guarantee is that all memory, allocated or free, will be released to the operating system when the program terminates.
The safe_delete macros aren't all that exciting. They check for a non-null pointer when it's perfectly safe to delete a null pointer, and setting the pointer to null afterward is only useful if the pointer is going to be reused and the code that reuses it actually examines the pointer before allocating the new memory. RAII and smart pointer are a much safer way to manage dynamic memory.
1. Memory allocator replacements that function as a garbage collector are available, but the emulator doesn't use them. I've been programming a long time and I've never seen them used.
|