Boaz Mohar
Boaz Mohar

Reputation: 182

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?

Upvotes: 8

Views: 1245

Answers (4)

Andy Brice
Andy Brice

Reputation: 2317

The original version of Purify on Unix was brilliant. But the Windows version produced after Rational bought it is terrible. Flakey as hell. Avoid at all costs.

Upvotes: 1

AlexC
AlexC

Reputation: 1415

On Windows:

Compuware BoundChecker (bit costly but very nice)

Visual LeakDetector (free, google it)

On Linux/Unix:

Purify

Upvotes: 4

R.Chatsiri
R.Chatsiri

Reputation: 107

If you use Anjuta,you can use valgrind module.

Upvotes: 0

Konrad Rudolph
Konrad Rudolph

Reputation: 546053

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.

Upvotes: 18

Related Questions