可以使用命令行使用Instruments吗?

可以使用仪器作为替代品

的valgrind

如果想要使用仪器检查内存泄漏是否可以从终端使用?

Instruments有一个命令行界面:

$ instruments -h 

用法示例:

 $ instruments -t mytemplate -a myapp.app 

对于泄漏,请尝试Leaks.tracetemplate 。 要查看所有可用模板,请使用-s

还有另一个可执行文件,称为leaks 。 您可以通过leaks其PID来检查任何正在运行的应用程序:

 $ ps aux | grep "[b]ash" | awk '{print $2}' 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. 

阅读Apple开发人员参考库中有关泄漏的更多信息。

对于Xcode 9,如果要分析iOS应用程序,请执行以下示例命令:

 instruments -t Zombies -w 'iPhone SE (11.0.1) [XXX] (Simulator)' MyApp.app 

仪器命令参考:

https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/Recording,Pausing,andStoppingTraces.html#//apple_ref/doc/uid/TP40004652-CH12-SW3