查找和调试废弃内存和堆增长的提示 [英] Tips for finding and debugging abandoned memory and heap growth

查看:109
本文介绍了查找和调试废弃内存和堆增长的提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近观看了WWDC 2010视频之一:会话311 - 使用乐器进行高级内存分析。该链接是此处

I recently watched one of the WWDC 2010 videos: Session 311 - Advanced Memory Analysis with Instruments. The link is here.

有关寻找遗弃记忆的视频中有一个有趣的例子。他们说调试通常比泄漏更重要,但可能更难。

There is an interesting example in the video on finding Abandoned Memory. They say that it is often more important to debug than leaks but can be more difficult.

废弃内存定义为永远不会再使用的可访问分配内存。

Abandoned Memory is defined as "Accessible allocated memory that is never used again".

定义泄漏作为无法再达到分配的内存。

A leak is defined as "Allocated memory that can no longer be reached."

查找弃置内存的主要方法是使用分配工具进行堆镜头。

The primary way to find Abandoned Memory is to take heap shots using the Allocations instrument.

但是,在确定我的代码中已经放弃了内存之后,我发现很难确切地知道它来自哪里。

However, after determining that I have abandoned memory in my code, I have found that it is really difficult to find out exactly where it is coming from.

我正在寻找一些寻找遗弃记忆的好方法或资源。

I am looking for some good tips or resources for finding Abandoned Memory.

谢谢!

推荐答案

在Instruments中,您可以获取由快照标识的任何对象的调用堆栈。屏幕截图:

In Instruments, you can get a call stack for any object identified by a heapshot. Screenshot:

所以我们在这里得到的是一个人为的例子,我每次用户点击按钮时都会分配一个1MB的NSMutableData。在中下方窗格中,我有4个快照,并且我有一个扩展显示自上次快照以来创建但未发布的对象。我突出显示了一个1.25MB的非对象分配,在右侧窗格中,它显示了发生此分配的确切调用堆栈。关于右侧面板的一个技巧是沿底部的滑块 - 它控制堆栈帧的消除。如果要查看所有堆栈帧,请将其一直拖到右侧。灰色框架是那些没有源代码的框架,非灰色框架是您的代码(或代码中包含符号和来源的代码。)(另外,如果您没有看到面板上的右键,检查工具栏中的查看按钮。)您还在寻找其他什么信息?

So what we've got here is a contrived case where I allocate a 1MB NSMutableData everytime the user taps a button. In the center-bottom pane, I've got 4 heapshots, and I have one expanded to show the objects that were created but not released since the last heapshot. I've highlighted a 1.25MB "non-object" allocation, and in the right pane, it shows me the exact call stack where this allocation occurred. One trick about that panel on the right is the slider along the bottom -- it controls the elimination of stack frames. If you want to see all the stack frames, drag it all the way to the right. Grayed out frames are those for which you don't have source code, and non-grayed-out frames are your code (or code you have both symbols and source for.) (Also, if you're not seeing the panel on the right, check the "View" buttons in the toolbar.) What other information are you looking for?

这篇关于查找和调试废弃内存和堆增长的提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆