我必须在 Instruments 应用程序和 ObjectAlloc 中查看哪些指标,才能确定我的应用程序中是否存在内存泄漏?
我想“#Net”专栏是最有趣的,尽管我不太明白那是什么意思。 当前分配的对象总数? 即使我什么都不做,它也一直在变化。
是否有任何好的“经验法则”来查看是否存在内存泄漏?
I guess that the "# Net" column is the most interesting, although I don't really understand what that's supposed to mean. Total number of currently allocated objects? It changes all the time, even if I don't do anything.
Are there any good "rules of thumb" to see if there is an memory leak?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能会发现本教程很有帮助:http:// www.mobileorchard.com/find-iphone-memory-leaks-a-leaks-tool-tutorial/。
此外,还有一个静态分析器可以直接分析您的源代码: http://clang.llvm.org /StaticAnalysisUsage.html。
You may find this tutorial helpful: http://www.mobileorchard.com/find-iphone-memory-leaks-a-leaks-tool-tutorial/.
As well, there's a static analyzer available that analyzes your source code directly: http://clang.llvm.org/StaticAnalysisUsage.html.
一般来说,如果您的应用程序的内存占用在您完成所有基本操作一两次后继续增长,那么您可能会发生内存泄漏。 总内存占用量位于“Net Bytes”列中。 “总体”列包括程序整个运行过程中的每次分配,而“净”列则减去释放分配。
然而,根据我的经验,“Leaks”工具在捕获内存泄漏方面比 ObjectAlloc 好得多。 只需在 Xcode 中选择“Run > Start With Performance Tool > Leaks”并运行您的程序一段时间。 如果 Leaks 开始显示泄漏的块,那么您就出现了泄漏。 它会告诉您每次分配、保留、释放以及释放任何泄漏块的堆栈跟踪,并且您可以双击堆栈跟踪以跳转到代码中的该位置。 只需确保通过单击窗口底部“泄漏块”标签左侧的半阴影方形小按钮来打开“扩展详细视图”。 要获取分配列表,请单击将鼠标悬停在块地址上方时出现在块地址旁边的小“圆中三角”显示三角形。
In general, if the memory footprint of your app continues to grow after you've gone through all your basic operations once or twice then you probably have a memory leak. The total memory footprint is in the "Net Bytes" column. The "Overall" columns include every allocation in the entire run of your program, while the "Net" columns subtract out deallocations.
However, the "Leaks" instrument is much better than ObjectAlloc for catching memory leaks in my experience. Just select "Run > Start With Performance Tool > Leaks" in Xcode and run through your program for a while. If Leaks starts showing leaked blocks then you've got a leak. It will tell you the stack trace of every allocation, retain, release, and free of any leaked block, and you can double-click on the stack trace to jump to that spot in your code. Just make sure to turn on the "extended detail view" by clicking on the little half-shaded square button at the bottom of the window, just to the left of the "Leaked Blocks" label. To get the list of allocations, click the little "triangle in a circle" disclosure triangle that appears next to the block's address when you hover the mouse over it.