4

初めてのアプリをアプリ ストアに提出する準備が整いました。漏れをチェックし、デバイスでテストし、動作します。メモリが制御されていることを確認したかったので、割り当てを実行しましたが、悲しいかな、何も制御されていませんでした。

アプリの複数の領域をテストしましたが、ユーザーが継続して使用するとメモリが制御不能になりやすいいくつかの大きな領域に焦点を当てました。Allocations/Heapshots からの情報は読みにくいので、誰かがこの出力を Rosetta Stone してくれることを願っています。

できる限り詳細をお伝えするように努めますが、不十分な場合は大声で言ってください。さらに書きます。

アプリはメニューから始まります。ボタンをクリックすると、presentModalViewController を介してビューが表示されます。ビューが表示され、バックグラウンドでデータベースが開かれ、ランダムな行が選択されて保存されます。したがって、次のサイクル: [メイン メニュー] -> [ビューを開く] -> [ビューを閉じる] をクリックすると、メモリが毎回 10KB から 25KB の割合で増加します。

いくつかの考え:

  • ビューの一部は IB を介して作成され、一部のボタンはカスタム .png ファイルです。以前のビルドでは、これらのリソースの解放と再割り当てに問題があり、メモリ リークが発生したと読みました。
  • IB で最初に作成されたいくつかのボタンで、button.layer.borderWidth/borderColor/cornerRadius/backgroundColor を使用しています。これはノーノーですか?(それらを削除すると少しは役に立ちますが、問題はまだ現れます)。

好奇心旺盛な人のために、これは最大のヒープ成長のコール スタックです。

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

コードの一部が役立つと思われる場合は、お知らせください。前進しているように感じましたが、これはかなりがっかりしています。

ありがとう。

4

1 に答える 1

0

Heapshot を使用してメモリ クリープを見つけます。参照: bbum ブログ

基本的には、Instruments 割り当てツールを実行し、ヒープショットを取得し、コードの直感を実行して、別のヒープショットを 3 ~ 4 回繰り返す方法があります。これは、反復中に割り当てられ、解放されないメモリを示します。

結果を把握するには、個別の割り当てを確認してください。

オブジェクトの保持、解放、および自動解放が発生する場所を確認する必要がある場合は、インストゥルメントを使用します。

計測器で実行し、割り当てで「参照カウントの記録」をオンに設定します (オプションを設定するには、記録を停止する必要があります)。ピッカーを実行し、記録を停止し、そこで ivar (datePickerView) を検索し、ドリルダウンすると、すべての保持、解放、および自動解放が発生した場所を確認できます。

私はこれを何度も使用しましたが、本当に役に立ちました。幸運を祈ります。

于 2011-12-01T22:20:28.333 に答える