Even though Mehdi refers to a problem of leak detection as difficult, it is actually the easiest of the memory problems to detect. Most complications are related to the mix of different APIs and platforms, different memory models which dominated during the development of C++. All this can of worms still lives in the Windows API.
In the ideal situation, the problem is pretty simple: there is some memory allocation API. A detector hooks up the API, monitors all allocations and deallocations and calculates detailed balance for each object, that's basically it. In many environments, this is 100% reliable. In real life, the main problem is using mixed APIs, but still a leak detectors dig out all the leaky situations.
I would also recommend to look at Visual Leak Detector.
Somewhat more general class of memory tools is the
Memory Debugger, see
http://en.wikipedia.org/wiki/Memory_debugger[
^]. The Memory Debuggers can also address those
buffer overrun problems. Please see the memory tools list in the article referenced above.
In contrast to memory leaks,
buffer overflow or
buffer overrun problems are more difficult, at least with the unsafe way C++ works with pointers and arrays. Please see for more information and the techniques used to overcome the problem:
http://en.wikipedia.org/wiki/Buffer_overflow[
^].
I'm not personally familiar with the tools effectively helping to overcome the problems of buffer overflow with C++. Again, please look at the list of tools from the article on Memory Debuggers.
—SA