Can anyone give me any simple syntax for running OSX's leaks
tool for detecting memory leaks in a compiled C program? I'm on 10.8, so I'm running into serious compatibility issues with valgrind
.
Most of the stuff I've read about XCode's Leaks/Instruments involves being in an XCode environment -- not something I want to do for my C programs.
Is there a way I can just run leaks on a compiled C program from the command line? If not, are there any other reliable alternatives I can use while waiting for an updated version of valgrind, or do I have to set up a VM with a Linux distro?
Use the iprofiler
tool ( manpage ) by adding this to the start of your command line:
iprofiler -leaks -d $HOME/tmp
(where $HOME/tmp
is where you want the results written).
You can then open up the resulting .dtps
bundle using Instruments to check for leaks (or any of the other 4 checks that iprofiler
performs).
If you are using clang then compile with both -O3
and -g
(as clang doesn't support -pg
).
This seems to work (macOS Catlina 10.15.6):
cd /usr/local/lib
ln -s $(xcode-select -p)/usr/lib/libLeaksAtExit.dylib
leaks --atExit -- ./a.out
Best to remove the symlink when done.
References:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.