Previous Section  < Free Open Study >  Next Section

Leak #1

Mismatched new/delete calls in the constructor and destructor of a class. The obvious case of C++ memory leakage occurs when a developer dynamically allocates memory via new and forgets to explicitly clean up that memory with a call to delete. This can occur when an object is created on the heap and not explicitly cleaned up or, more commonly, when the constructor of a class dynamically allocates memory but the destructor is either absent or not cleaning up the object correctly. An example of the former case is shown here.

    Previous Section  < Free Open Study >  Next Section