Welcome to MacBoardz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

command line tool for finding mem leaks?

 
   Macintosh computer (Home) -> Tools RSS
Next:  fink and GLib version  
Author Message
ilya

External


Since: May 10, 2006
Posts: 1



(Msg. 1) Posted: Wed May 10, 2006 10:36 pm
Post subject: command line tool for finding mem leaks?
Archived from groups: comp>sys>mac>programmer>tools (more info?)

hello,

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.

thank you.

-- ilya

 >> Stay informed about: command line tool for finding mem leaks? 
Back to top
Login to vote
David Phillip Oste

External


Since: Apr 25, 2004
Posts: 974



(Msg. 2) Posted: Thu May 11, 2006 6:23 am
Post subject: Re: command line tool for finding mem leaks? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article ,
ilya 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.)

 >> Stay informed about: command line tool for finding mem leaks? 
Back to top
Login to vote
Sebastian Roth

External


Since: May 25, 2006
Posts: 1



(Msg. 3) Posted: Thu May 25, 2006 10:28 am
Post subject: Re: command line tool for finding mem leaks? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hi,

On 2006-05-11 07:36:28 +0200, ilya said:
> 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.

I'm not sure if its ported, but we used `valgrind` a lot on some unix
boxes and i strongly recommend it.

Regards,
Seb
 >> Stay informed about: command line tool for finding mem leaks? 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
file descriptor leaks - Hi, anybody know of a tool that can tell me where in my code a file descriptor leak happens? It's a objective-c/cocoa application on MacOs X 10.3.7 thanks Ole Andre Karlson oleaka@ifi.uio.no http://heim.ifi.uio.no/~oleaka

tool to reformat text? - I have just inherited a project that I will now be responsible for. The prior programmer used spaces to indent, while I strongly prefer tabs. Is there any program out there to go through and properly reformat the existing code? Note that I don't want....

Mac OS X equiv of MPW Canon Tool - Can (will) someone tell me if there is an equivalent to the MPW Canon tool in, or for, Mac OS X.

Debugging tool to complete gcc and gdb on OS X - We are porting a compiler to OS X (poplog compiler) and have to deal with a lot of assembly to trace and debug. We can trace the execution with gdb of the assembly code generated by gcc with the -g option, but can't see the content of registries as we d...

Memory Debugger Tool - Hey, i need a tool that helps me to find an error in a ported X11 application. Is there anything like valgrid or purify available ?
   Macintosh computer (Home) -> Tools All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]