iPhone:工具配置稳步增长
我将仪器与分配仪器一起使用。我只测试与我的应用程序的固定交互。
我有一个 4 级深度的导航控制器。前两个阶段是标准表视图控制器,后两个阶段是具有动态加载图像的自定义控制器。
因此,我在仪器中运行我的应用程序(通过使用性能工具运行 -> 分配)并进行以下交互:
1. App Loads
2. I wait a bit until allocations graph stabilizes
3. I tap/push into my navigation controller until the deepest level.
4. I wait for the images to load and for the allocations graph to stabilize.
5. I tap back out of the navigation controller until I'm back to the root level.
6. I wait for the allocations graph to stabilize.
7. GOTO 3.
现在我注意到,在 3 到 7 的每次迭代之间,分配图显示的值略高。因此,即使我在做同样的事情并且所有视图控制器的释放都被调用,总体分配仍在增加。
所以时间线看起来大致是这样的:
1. Start: 1mb
2. Push controllers/Load images: 4mb
3. Pop controllers: 1.1mb
4. Push controllers/Load images: 4.1mb
5. Pop controllers: 1.2mb
6. ... etc ... (always increasing slightly)
所以我的问题是这是否意味着我有泄漏或者这是正常的吗?另外,分配图数据实际上代表什么?为什么即使我回到初始状态,价值仍在增加?我担心如果我的应用程序运行足够长的时间,即使用户所做的只是推送和弹出视图控制器,它也会消耗太多内存。
任何想法都会有帮助。
I'm using Instruments with the Allocations instrument. I'm testing only a fixed interaction with my app.
I have a navigation controller which goes 4 stages deep. The first two stages are standard table view controllers and the last two are custom controllers with dynamically loaded images.
So I run my app in instruments (via Run with Performance Tool -> Allocations) and do the following interactions:
1. App Loads
2. I wait a bit until allocations graph stabilizes
3. I tap/push into my navigation controller until the deepest level.
4. I wait for the images to load and for the allocations graph to stabilize.
5. I tap back out of the navigation controller until I'm back to the root level.
6. I wait for the allocations graph to stabilize.
7. GOTO 3.
Now what I've noticed is that between each iteration from 3 to 7 the allocations graph shows a slightly higher value. So the overall allocations are increasing even though I'm doing the same thing and all the view controller's deallocs are being called.
So the timeline looks roughly like this:
1. Start: 1mb
2. Push controllers/Load images: 4mb
3. Pop controllers: 1.1mb
4. Push controllers/Load images: 4.1mb
5. Pop controllers: 1.2mb
6. ... etc ... (always increasing slightly)
So my question is does this mean I have a leak or is this normal? Also what does the allocations graph data actually represent? And why is the value increasing even though I'm popping back out to the initial state? I'm worried that if my app runs long enough it will consume too much memory even though all the user is doing is pushing and popping view controllers.
Any thoughts would be helpful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是在模拟器中还是在设备上?
由于某些系统库在设备上比在模拟器中更频繁地释放内存,因此最好验证设备上是否存在问题。
如果 Leaks 没有显示任何内容,那是因为您仍然在某处保留了对内存的引用,即使您认为自己不是这样。为了帮助追踪这一点,请突出显示图表中内存增加的一小部分,然后选择“已创建且仍然有效”。现在您可以只看到分配的内存,并开始追踪问题所在。
Is this in the simulator, or on the device?
As it's good to verify a problem exists on the device, as some system libraries release memory more often on the device than in the simulator.
If Leaks shows nothing, it's because you are still holding a reference to memory somewhere even if you don't think you are. To help track that down, highlight a small portion of the graph where the memory is increasing, and select "created and still living". Now you can see just the memory allocated, and start to track down just where the issue is.
如果您有最新的 iPhone SDK,它附带的 Instruments 版本(我相信是 2.7)具有 HeapShot 功能。您可以观看一些 WWDC '10 视频以获取更多信息,但本质上您是在第一次弹出控制器时拍摄一次,然后在第二次弹出时再次拍摄。它将向您显示这两个时刻不同的内存分配。
If you have the newest iPhone SDK, the version of Instruments it comes with (2.7 I believe) has a HeapShot feature. You can watch some of the WWDC '10 videos for more information, but essentially you take a shot the first time you pop controllers and then again when you pop a second time. It will show you any memory allocations that are different at the two moments.
你可能有泄漏。检查泄漏仪器,它可以帮助您找到它们。
You probably have a leak. Check the leaks instrument which can help you find them.
是的,这是一个泄漏。你的一个视图控制器丢失了一些东西。
Yes, this is a leak. One of your view controllers along the line is missing something.
如果您正在加载图像,那么您很有可能正在使用 [UIImage imageNamed:] ,这会导致系统缓存,并且可能是内存使用的原因。但简而言之,是的,你有泄漏。
If you are loading images then there is a good chance you are using [UIImage imageNamed:] that causes the system to cache and may be a cause of your memory use. But in short yes, you have a leak.