PDA

View Full Version : Memory leak/error tool for OS X?



miggles
08-15-2004, 03:30 PM
I use Rational Purify all the time at work, but it's only available for SunOS, Irix, redhat, and windows. Can anyone recommend a similar tool for OS X? I have seen a code called OmniObjectMeter, but it looks like it can only handle full-fledged applications which have been linked through Project Builder, not simple command line linked applications (e.g. an a.out which links in nothing and prints "hello world" to the terminal).

Also, I have a long standing problem with debug-compiled (-g) objects which essentially makes gdb inconvenient and useless. Whenever I enter gdb, I always have to provide it the directories where the original source code objects are located. This is not trivial when I am linking in several dozen libraries or building different variants of codes under different source trees. Is there a way for gcc to encode the full paths into the objects to make gdb less cumbersome?

Thanks.

witeshark
08-15-2004, 10:56 PM
Memory leaks issues are one of the very best strong points of OS X: there are none that I have ever heard of and it's why the force quit app can safely stop a locked or looping app without affecting the rest of the system

miggles
08-16-2004, 12:33 AM
I'm not so concerned about system level memory leaks as opposed to application level leaks. Imagine calling a C++ method that does nothing but allocate space, use it locally, but never delete it. Even though the system is safe from being harmed by this, the application may eventually kill itself when space runs out.


void Blort()
{
int *a = new int [10000];
a[0] = 5;
}

int main()
{
while (1)
Blort();
return 0;
}

witeshark
08-16-2004, 12:52 AM
miggles, application level leaks. Dude There's the difference!

dr_springfield
08-18-2004, 08:01 AM
http://developer.apple.com/documentation/Darwin/Reference/ManPages/html/leaks.1.html

But I've never used it. I typically use the memory management tools that come with Xcode. In one of the menus (not on a mac right now so I cant say exactly)... Debug probably, you'll see "Run with..." and there are several apps in there. The one that has the icon that looks like a melting icecube is my favorite. Wish I could tell you the name, but my brain is goo.

miggles
08-18-2004, 01:12 PM
Thanks for the pointer dr_springfield. Unfortunately, that doesn't seem able to work with plain vanilla g++ compiled code either:

% leaks ./a.out
leaks cannot find a process you have access to which has a name like './a.out'


Also, is there anything to trap memory errors such as UMRs (uninitialized memory reads) or FMRs (freed memory reads) as they happen? I'm interested in something that doesn't require the target application to link in the Carbon lib because I am working with codes that compile on multiple architectures (mainly different flavors of Unix). Thanks.

dr_springfield
08-21-2004, 12:22 PM
Thanks for the pointer dr_springfield. Unfortunately, that doesn't seem able to work with plain vanilla g++ compiled code either:

% leaks ./a.out
leaks cannot find a process you have access to which has a name like './a.out'

Just tested this out.
Leaks only works on running executables. It's irritating, but you can just make your code wait for input when you want to check for memory leaks, and then run the command then.
Also check out the "heap" and "malloc_history" commands.


Also, is there anything to trap memory errors such as UMRs (uninitialized memory reads) or FMRs (freed memory reads) as they happen? I'm interested in something that doesn't require the target application to link in the Carbon lib because I am working with codes that compile on multiple architectures (mainly different flavors of Unix). Thanks.

gdb should handle this, shouldn't it? I'm not particularly good with gdb... I just sort of use it to do exactly what I have to do and don't know the entire massive extent of it's capabilities, but it seems like you could get that sort of info from gdb.