了解iOS仪器 [英] Understanding iOS Instruments

查看:115
本文介绍了了解iOS仪器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个iPhone应用程序。遇到内存问题我开始使用Instruments来追踪任何内存问题。我遇到了一些奇怪的行为,导致我误以为我误用了仪器或误读了数据。

I am creating an iPhone app. Running into memory issues I started using Instruments to track down any memory problems. Am running into some strange behavior that leads me to believe that I am either mis-using Instruments or mis-reading its data.

这些是搬入时记录的LiveBytes值并离开某个位置:

These are the LiveBytes values recorded when moving in and out of a location:

**Expensive Location-**
World (12 MB)
Loc (27 MB)
World (13 MB )
Loc (28 MB)
World (14 MB)
-Crash

**Cheap Location-**
World (12 MB)
Loc (23 MB)
World (13 MB )
Loc (24 MB)
World (14 MB)
-Crash

请注意,即使廉价位置的内存已经到达附近,我仍然会崩溃昂贵的地点记忆。有人可以帮我吗?

Notice how I still crash even though the cheap location's memory has come no where near the expensive locations memory. Could anyone help me out here?

推荐答案

我不确定这是否与您遇到的问题有关但我希望如此帮助:我最近跟踪应用程序的内存占用情况,我注意到即使在UINavigator控制器上点击返回后dealloc消息被发送到视图控制器,我仍然有几十个活动对象留在这里操作(您可以在仪器应用程序的分配面板中看到这一点)。为了解决这个问题,我使用了以下几种方法:

I'm not sure if this is related to the problem you have but I hope it helps: I was recently tracking the memory footprint of an app and I noticed that even though the dealloc message was being sent to a view controller after hitting "back" on the UINavigator controller, I still had a few dozen live objects left over from this operation (you can see this in the 'Allocations' panel of the instruments app). To solve this I used a mix of a few things:

首先,我将以下三种方法添加到NSLog我的自定义子视图的保留计数器(可在此处找到 iOS4 - 快速上下文切换):

First, I added the following three methods to NSLog the retain counters of my Custom subviews (found here on SO at iOS4 - fast context switching):

#pragma mark - RETAIN DEBUG MAGIC
// -----------------------------------------------------------------------------

- (id)retain
{
  NSLog(@"retain \t%s \tretainCount: %i", __PRETTY_FUNCTION__ , [self retainCount]);
  return [super retain];
}
- (void)release
{
  NSLog(@"release \t%s \tretainCount: %i", __PRETTY_FUNCTION__ , [self retainCount]);
  [super release];
}
- (id)autorelease
{
  NSLog(@"autorelease \t%s \tretainCount: %i", __PRETTY_FUNCTION__ , [self retainCount]);
  return [super autorelease];
}

然后,我隔离了每个视图构建块,只留下一个简单的任务(例如,将UIButton作为子视图加载)并返回到仪器应用程序以跟踪活动对象(在Xcode中的Product> Profile下)并禁用具有'NS','CF'和'malloc'前缀的所有对象(您可以单击分配选项卡旁边的小 i 按钮来执行此操作。在此之后,在右下方窗格中选择呼叫树并继续钻孔,直到我找到了一些物体计数器上升的地方,因为我来回导航。

Then, I isolated each one of the view building blocks leaving only one simple task (for example loading a UIButton as a subview) and went back to the instruments app to track the live objects (under Product > Profile in Xcode) and disabled all the objects with 'NS', 'CF' and 'Malloc' prefixes (you can do this clicking on the little i button next to the 'Allocations' tab). After this, selected "Call Trees" on the bottom right pane and kept drilling until I found a few places where the object counter went up as I navigated back and forth.

请注意,您可以双击符号以查看与对处理器进行的调用相关的详细信息。此外,单击小 i 图标将弹出一个突出显示的呼叫的回溯。

Notice that you can double click on the symbol to see the details related to the calls made to the processor. Additionally, clicking on the little i icon will bring a pop up with the backtraces for the highlighted call.

当查看回溯时,您将看到他们中的一些人有一个小图标,描绘一个人在一个框架上(这些图标旁边的文字作为视觉提示明显更暗)。双击这些将带您到代码中负责此次通话的行。

When looking at the backtraces you will see that some of them have a small icon that depicts a person on a frame (the text next to these icons is significantly darker as a visual cue). Double clicking on these will take you to the line in your code responsible for this call.

以下是一些链接,可以帮助您了解有关乐器的更多信息:

Below are a few links that might give you a hand in understanding more about instruments:

http://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/ViewingandAnalyzingData/ViewingandAnalyzingData.html

注意:
在旅程结束时,我所要做的就是释放我的将它们添加到超级视图后的视图他们会被解雇。即,

Note: At the end of my journey, all I had to do was release my views after adding them to their 'super' views to ensure they would be dealloc'd. i.e.,

[[self view] addSubView:aButton];
[aButton release];

这篇关于了解iOS仪器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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