Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to check for memory leaks in c++?

I'm implementing a sparse matrix with linked lists and it's not fun to manually check for leaks, any thoughts?

like image 985
Boaz Mohar Avatar asked Dec 28 '08 11:12

Boaz Mohar


2 Answers

The valgrind profiler for Unix offers a decent leak detection.

However, this is only one part of a successful approach. The other part is to prevent (i.e. minimize) explicit memory handling. Smart pointers and allocators can help a great deal in preventing memory leaks. Also, do use the STL classes: a leak-free linked list implementation is already provided by std::list.

like image 192
Konrad Rudolph Avatar answered Nov 15 '22 22:11

Konrad Rudolph


On Windows:

Compuware BoundChecker (bit costly but very nice)

Visual LeakDetector (free, google it)

On Linux/Unix:

Purify

like image 29
AlexC Avatar answered Nov 15 '22 22:11

AlexC