了解 iOS 仪器

发布于 2024-11-07 04:02:05 字数 403 浏览 0 评论 0原文

我正在创建一个 iPhone 应用程序。遇到内存问题我开始使用 Instruments 来追踪任何内存问题。我遇到了一些奇怪的行为,这让我相信我要么误用了仪器,要么误读了其数据。

这些是移入和移出某个位置时记录的 LiveBytes 值:

**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

请注意,即使廉价位置的内存与昂贵位置的内存相差甚远,我仍然会崩溃。有人可以帮我吗?

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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千柳 2024-11-14 04:02:05

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

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

#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 中的“产品 > 配置文件”下)并禁用所有带有“NS”、“CF”和“Malloc”前缀的对象(您可以单击小i 按钮位于“分配”选项卡旁边)。之后,选择右下窗格中的“调用树”并继续钻取,直到我发现来回导航时对象计数器上升的几个位置。

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

当查看回溯时,您会发现其中一些有一个小图标,在框架上描绘了一个人(这些图标旁边的文本明显更暗,作为视觉提示)。双击这些将带您到代码中负责此调用的行。

下面的一些链接可能会帮助您了解有关仪器的更多信息:

注意:
在我的旅程结束时,我所要做的就是在将我的视图添加到“超级”视图中后发布它们,以确保它们被释放。 IE,

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

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:

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];
}

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.

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:

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文