2011-12-01 111 views
4

我已经准备好将我的第一个应用提交给应用商店。检查泄漏情况,在设备上进行测试。我想确保我的记忆力得到控制,所以我跑分配,而且,唉,什么都没有控制。iPhone应用内存不断增长

我测试了我的应用程序的多个区域,但我专注于几个大的区域,用户继续使用可能会使内存非常容易失控。对我来说,来自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 

如果你想的码位会有所帮助,请让我知道。我感觉自己正在向前迈进,这令人非常沮丧。

谢谢。

回答

0

使用Heapshot查找内存creap,请参见:bbum blog

基本上有方法是运行仪器分配工具,取heapshot,运行代码的直觉和另一heapshot重复3或4次。这将指示在迭代过程中分配并未释放的内存。

为了弄清楚结果是否披露了个别分配。

如果你需要看到保留,发布和自动释放出现一个对象使用仪器:在仪器

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

我已经使用过很多次,它真的帮助,祝你好运。

+4

对,这就是我所做的(这是我如何提出上面提到的数字)。我不能破译任何它,但一切似乎都是内在的,并不直接指向我的任何方法。 – ballofpopculture

+0

这里同样的问题。 – dan