Re: command line tool for finding mem leaks?
- From: David Phillip Oster <oster@xxxxxxxx>
- Date: Thu, 11 May 2006 06:23:29 GMT
In article <Pine.OSX.4.64.0605102222360.1466@xxxxxxxxx>,
ilya <ilyamoskovko@xxxxxxxxx> wrote:
can anybody recommend me a tool that will automatically detect
memory leaks in my c++ code compiled with g++. i'm looking for
something similar to what bcheck or dbx does [when you do
'check -leaks']. if it can identify actual lines in code where
the leak(s) occur that would be even better.
i had no luck with gdb; i know there is the leaks command but
i'm not exactly sure how to use it on my program. i have tried
some other tools, including MallocDebug, but couldn't get any
of them to work on my intel based mac.
Did you type into a Terminal window:
man leaks
?
As the man page says, you'll want to set the environment variable
MallocStackLogging = 1, so leaks will give you a human readable dump of
the top few stack frames of the allocation of each leak.
I usually do a command in the program under test, then in a Terminal
window, while my program is still running, but idle, do:
ps ax -- to find the process id number {pid}
leaks {pid} > take1.txt
then do the command a second time, and do:
leaks {pid} > take2.txt
then use FileMerge to see what is different between the two files. Any
allocations made by the second pass and not cleaned up will jump out at
you.
Once you know who allocate the blocks that leak, you can look for the
highest level structure that owns some leaking blocks, then look for
what should have deallocated it. Very common:
foo = fum;
which should be:
if(foo != fum){
delete foo;
foo = fum;
}
Note: if you are using Cocoa, you must turn off NSZombie, since cocoa's
Zombie detection requires "leaking" every block ever allocated as far as
your program is concerned (blocks you free are kept on a list so that
accesses after death can be tracked.)
.
- References:
- command line tool for finding mem leaks?
- From: ilya
- command line tool for finding mem leaks?
- Prev by Date: command line tool for finding mem leaks?
- Next by Date: Re: fink and GLib version
- Previous by thread: command line tool for finding mem leaks?
- Next by thread: Re: command line tool for finding mem leaks?
- Index(es):
Relevant Pages
|