N
Nelson Davenapalli
What are the best ways of debugging your c++ program.
Subject: Re: what is the best way to identify memory leaks in a C++ code.
What are the best ways of debugging your c++ program.
What are the best ways of debugging your c++ program.
Ian Collins said:Using a debugger works reasonably well.
Writing your tests before you code is better still.
Most debuggers don't detect memory leaks. You need a specialized tool
for that such as valgrind.
Unit tests are great but...
In my experience, it's far more tricky to write (and utilise) unit
tests for memory usage than for most other sorts of correctness (i.e.
"did I get the correct answer?"). It's certainly not impossible
because
i) "slow puncture" memory leaks may well not leak noticeable amounts
of memory in hourly time periods. In my experience unit test work
best when couple to a fast code-compile-test cycle. (Of course, a
valgrind run is not exactly lightning fast).
I run tests with a custom allocator that can be checked in the test
tearDown. Once in a while (before sharing my changes) I run them in the
debugger with access checking enabled.
Oh, OK, that makes sense. But unfortunately, the process now starts
"First write your custom allocator...".
I guess the obvious middle-ground is to use the valgrind hooks instead
of a custom allocator, and have a unit test in the form of "valgrind
run doesn't report any memory leaks".
Oh, OK, that makes sense. But unfortunately, the process now starts
"First write your custom allocator...".
I guess the obvious middle-ground is to use the valgrind hooks instead
of a custom allocator, and have a unit test in the form of "valgrind
run doesn't report any memory leaks".
The last updates on those files were in 2001!
Assuming Linux, which I don't use....
Well, sure, its the perfect candidate for code resuse, but that
doesn't help until you've actually put the legwork in first (even if
it was 11 years ago).
"Valgrind" here can be considered a placeholder for "widely available
memory leak detector". Purify, maybe.
Out of interest, can your custom allocator detect malloc'd pointers
that have been lost (like a GC, say), or just those that are un-free'd
at teardown?
what is the best way to identify memory leaks in a C++ code.
what is the best way to identify memory leaks in a C++ code[?]
On 05/25/12 09:10 PM, gwowen wrote: .... ....
I must admit I don't use it much with new code where every pointer is
owned by an object that looks after it.
gwowen said:"Valgrind" here can be considered a placeholder for "widely available
memory leak detector". Purify, maybe.
The last updates on those files were in 2001!Assuming Linux, which I don't use....
It works on OS X now, too. Although there have been some glitches with Lion.
Still, it's [theoretically] maintained and on equal footing with Linux.
But maybe you're referring to Solaris or Windows or z/OS....
If you are running in the windows visual studio environment
take a look at "Visual Leak Detector".
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.