Can Instruments be used as a replacement for
valgrind
If one wants to check for memory leaks using instruments can it be used from the terminal?
Press Command-I in Xcode, select Allocations from the list and press Choose. After a moment, you'll see the Allocations instrument. It should look familiar because it looks a lot like Time Profiler. Click the record button in the top-left corner to run the app.
Launch Instruments from the Dock: Control-click the Xcode icon in the Dock, and then choose Options > Open Developer Tool > Instruments from the shortcut menu to launch Instruments.
"Instruments" is an application provided by Apple that provides a graphical user interface for the DTrace command-line tool. DTrace is a troubleshooting tool available on several Unix-like operating systems, including Mac OS X. It can log and provide statistics for many application and kernel-level operations.
Instruments is a performance-analysis and testing tool for iOS, iPadOS, watchOS, tvOS, and macOS apps.
Instruments has a command line interface:
$ instruments -h
Example usage:
$ instruments -t mytemplate -a myapp.app
For leaks, try the Leaks.tracetemplate
. To see all available templates, use -s
.
There is another executable, just called leaks
. You can inspect any running application by giving leaks
its PID:
$ echo $$
620
$ leaks 620
leaks Report Version: 2.0
Process: bash [620]
Path: /bin/bash
Load Address: 0x100000000
...
Process 620: 37983 nodes malloced for 1123 KB
Process 620: 0 leaks for 0 total leaked bytes.
Read more about leaks in the Apple developer reference library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With