我的应用程序即将完成,在提交到应用程序商店之前,我正在使用 Instruments 来优化性能。我注意到,每当我执行特定操作(从外部服务器更新应用程序中的信息)时,我的堆就会增长约 350 KB。我在 stackoverflow 和 Apple 文档中发现的研究建议执行堆扫描来查找有问题的代码。然而,它并没有带我到有问题的代码,而是显示了内存地址。
有没有办法使用这些信息?或者我应该使用其他工具?我对仪器还很陌生,所以我很感激任何帮助。
我会展示一个屏幕截图,但我在这里的声誉还不够高。
有几点想法:
-
In the heap shot, don't forget to show the extended detail (⌘+E or select "Extended Detail" from the "View" menu) in the rightmost panel of Instruments.
查看扩展详细信息时,它将向您显示堆栈跟踪,您可以双击那里的方法名称(它将是黑色而不是浅灰色),您将被带到生成分配的行(显然不一定是根本问题,但它会向您显示对象最初分配的位置,这是一个开始的地方)。
![view extended detail in heapshot analysis](https://i.stack.imgur.com/bsKaC.png)
-
Having said that, I generally focus on the standard Allocations tool first. I'll option-drag in the allocations instrument timeline at the top to highlight allocations within this time window of execution, I'll then select "Call Tree", and to focus on just my code, I'll check the "Invert Call Tree" and "Hide System Libraries" boxes:
![option drag in allocations tool](https://i.stack.imgur.com/5jwpk.png)
对我来说,我发现这是一种更有效的方法来识别在该时间窗口内发生的分配,而无需筛选系统分配。
Do not forget to run your code through the static analyzer in Xcode (shift+⌘+B or choose "Analyze" on the "Product" menu). You should get a clean bill of health there before you even start running your app through Instruments.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)