All good C++ programmers know how to avoid leaking memory (or resources like sockets):
- Always use smart pointers, i. e.:
std::auto_ptr
,boost::shared_ptr
. - Always be aware of ownership of object: who owns, who refers, who is responsible, etc.
But, memory leaks still happen. Point most common issues when you discovered a memory leak in a program, even when you used the above techniques.
I start:
Sometimes you forget to define a destructor of base class as virtual. So all derived classes referred by pointer to the base class which was not destroyed properly and therefore leaked.