iPhone应用程序内存不断增长

时间:2011-12-01 22:09:09

标签: iphone ios memory-management xcode-instruments allocation

我已准备好将我的第一个应用程序提交到应用程序商店。检查泄漏,在设备上测试,工程。我想确保我的记忆得到控制,所以我进行了分配,唉,没有任何东西可以控制。

我测试了我的应用程序的多个区域,但我专注于几个大的区域,用户继续使用可能会使内存失控很容易。对我来说,Allocations / Heapshots中的信息很难读懂,所以我希望有人可以为我提供Rosetta Stone这个输出。

我会尝试尽可能多地提供详细信息,如果还不够,那就大喊大叫,我会写更多。

应用程序从菜单开始。单击按钮可通过presentModalViewController显示视图。视图出现并在后台打开数据库并选择并存储随机行。因此循环:点击主菜单 - >打开视图 - >关闭视图使我的记忆每次以10KB-25KB的速度增长。

一些想法:

  • 我视图的某些部分是通过IB创建的,包含一些按钮 是自定义的.png文件。我读到早期版本有问题 释放并重新分配导致内存泄漏的这些资源。
  • 我一直在使用button.layer.borderWidth / borderColor / cornerRadius / backgroundColor以及我最初在IB中创建的一些按钮。这是不是吗? (删除它们确实有点帮助,但问题仍然存在)。

对于那些好奇的人来说,这是堆增长最大的调用堆栈:

0 libSystem.B.dylib calloc
1 CoreGraphics CGGlyphBitmapCreate
2 CoreGraphics CGFontCreateGlyphBitmap8
3 CoreGraphics CGFontCreateGlyphBitmap
4 CoreGraphics CGGlyphLockLockGlyphBitmaps
5 libRIP.A.dylib ripc_DrawGlyphs
6 CoreGraphics draw_glyphs
7 CoreGraphics CGContextShowGlyphsWithAdvances
8 WebCore WebCore::showGlyphsWithAdvances(WebCore::FloatPoint const&, WebCore::SimpleFontData const*, CGContext*, unsigned short const*, CGSize const*, unsigned long)
9 WebCore WebCore::Font::drawGlyphs(WebCore::GraphicsContext*, WebCore::SimpleFontData const*, WebCore::GlyphBuffer const&, int, int, WebCore::FloatPoint const&, bool) const
10 WebCore WebCore::Font::drawSimpleText(WebCore::GraphicsContext*, WebCore::TextRun const&, WebCore::FloatPoint const&, int, int) const
11 WebCore WebCore::Font::drawText(WebCore::GraphicsContext*, WebCore::TextRun const&, WebCore::FloatPoint const&, int, int) const
12 WebKit drawAtPoint(unsigned short const*, int, WebCore::FloatPoint const&, WebCore::Font const&, WebCore::GraphicsContext*, bool, WebCore::BidiStatus*, int)
13 WebKit -[NSString(WebStringDrawing) __web_drawAtPoint:forWidth:withFont:ellipsis:letterSpacing:includeEmoji:measureOnly:renderedStringOut:drawUnderline:]
14 WebKit -[NSString(WebStringDrawing) __web_drawAtPoint:forWidth:withFont:ellipsis:letterSpacing:includeEmoji:measureOnly:renderedStringOut:]
15 WebKit -[NSString(WebStringDrawing) __web_drawAtPoint:forWidth:withFont:ellipsis:letterSpacing:includeEmoji:measureOnly:]
16 WebKit -[NSString(WebStringDrawing) _web_drawAtPoint:forWidth:withFont:ellipsis:letterSpacing:includeEmoji:]
17 UIKit -[NSString(UIStringDrawing) drawAtPoint:forWidth:withFont:lineBreakMode:letterSpacing:includeEmoji:]
18 UIKit -[NSString(UIStringDrawing) drawAtPoint:forWidth:withFont:fontSize:lineBreakMode:baselineAdjustment:includeEmoji:]
19 UIKit -[NSString(UIStringDrawing) drawAtPoint:forWidth:withFont:fontSize:lineBreakMode:baselineAdjustment:]
20 UIKit -[UILabel _drawTextInRect:baselineCalculationOnly:]
21 UIKit -[UILabel drawTextInRect:]
22 UIKit -[UILabel drawRect:]
23 UIKit -[UIView(CALayerDelegate) drawLayer:inContext:]
24 QuartzCore -[CALayer drawInContext:]
25 QuartzCore backing_callback(CGContext*, void*)
26 QuartzCore CABackingStoreUpdate_
27 QuartzCore CA::Layer::display_()
28 QuartzCore -[CALayer _display]
29 QuartzCore CA::Layer::display()
30 QuartzCore -[CALayer display]
31 QuartzCore CA::Layer::display_if_needed(CA::Transaction*)
32 QuartzCore CA::Context::commit_transaction(CA::Transaction*)
33 QuartzCore CA::Transaction::commit()
34 QuartzCore CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*)
35 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
36 CoreFoundation __CFRunLoopDoObservers
37 CoreFoundation __CFRunLoopRun
38 CoreFoundation CFRunLoopRunSpecific
39 CoreFoundation CFRunLoopRunInMode
40 GraphicsServices GSEventRunModal
41 GraphicsServices GSEventRun
42 UIKit UIApplicationMain
43 GRE Words main /Users/admin/Dropbox/GRE Words/main.m:14
44 GRE Words start

如果你认为有些代码会有所帮助,请告诉我。我觉得自己正在向前迈进,这令人非常沮丧。

感谢。

1 个答案:

答案 0 :(得分:0)

使用快照查找内存折痕,请参阅:bbum blog

基本上有一种方法是运行仪器分配工具,获取快照,运行代码直观和另一个快照重复3或4次。这将指示在迭代期间分配但未释放的内存。

要弄清楚披露的结果,以查看个别分配。

如果您需要查看对象使用仪器的保留,释放和自动释放的位置:

在仪器中运行,在分配中设置“记录参考计数”(您必须停止记录以设置选项)。导致选择器运行,停止记录,搜索那里的ivar(datePickerView),向下钻取,你将能够看到所有保留,释放和自动释放发生的位置。

我已多次使用它,它确实有所帮助,祝你好运。