views:

241

answers:

1

I want to use the MallocDebug app to find some memory leaks in my app. I'm running Mac OS X 10.6.2. Whenever I try and following the instructions listed in this guide, I get the following error:

dyld: could not load inserted library: /usr/lib/libMallocDebug.A.dylib

Trace/BPT trap

I have verified that the .dylib file exists, and I get the same error no matter which app I try and run (it's not limited to my application). Several others have reported this problem as well, but so far no one has found a solution.

Any ideas?

+4  A: 

libMallocDebug is not available for 64-bit executables.

% lipo -info /usr/lib/libMallocDebug.A.dylib    
Architectures in the fat file: /usr/lib/libMallocDebug.A.dylib are: i386 ppc7400 

It does appear to work with 32-bit executables in 10.6, though, for example:

% lipo -thin i386 /bin/ls -out foo
% DYLD_INSERT_LIBRARIES=/usr/lib/libMallocDebug.A.dylib ./foo        
libMallocDebug[foo-9141]: initializing libMallocDebug on thread 903
[...]

I'm not sure whether this is an oversight or it was never ported to the 64-bit runtime. You might try filing a bug.

Update: Seems there are just more debugging features in the regular malloc now. This discussion is pretty good.

Nicholas Riley
I have just now filed a bug - Are there any alternative tools I can use, since this one seems to be unavailable?
Thomi
You can't just compile your app as 32-bit? There is the `leaks` command-line tool. Valgrind kinda works with Snow Leopard but may not work to your satisfaction (you'll need to build it yourself; see the discussion at https://bugs.kde.org/show_bug.cgi?id=205241).
Nicholas Riley
not really. According to apple, the MallocDebug method is being deprecated, in favour of the Instruments application, although I personally can't seem to get that particular app to do anything sensible.
Thomi