我已经准备好将我的第一个应用程序提交到应用商店。检查泄漏,在设备上测试,工作。我想确保我的内存在控制之下,所以我运行了分配,唉,没有什么是在控制之下的。
我已经测试了我的应用程序的多个区域,但我专注于几个大区域,用户继续使用这些区域可能会使内存很容易失控。对我来说,来自 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
如果您认为一些代码会有所帮助,请告诉我。我觉得我在前进,这非常令人沮丧。
谢谢。