UIViews
単一の のセット内に配置されたラベルのセットがありUIScrollView
ます。コンセントが割り当てられていません。私はそれらすべてに Avenir Next Ultralight フォントを使用していますが、サイズはさまざまです。
メイン ビューには、ナビゲーション コントローラーにネストされた単一のビュー コントローラーがあります。
割り当てのチェックを実行していたところ、ロード時にこの単一のビューで約 10MB のメモリが消費され、そのうち 8MB がこれらのラベルであり、次のビューに移動すると、その割り当ては有効なままであることに気付きました。
何が原因でしょうか?
これは、割り当ての記録からのスナップショットです。
Snapshot Timestamp Growth # Persistent
VM: UILabel (CALayer) 7.90 MB 10
0x5417000 00:02.950.428 1.23 MB
0x5553000 00:02.967.675 1.23 MB
0x568f000 00:02.978.283 1.23 MB
0x591d000 00:03.013.095 832.00 KB
0x57cb000 00:03.004.334 832.00 KB
0x50a7000 00:02.919.040 832.00 KB
0x5177000 00:02.937.076 832.00 KB
0x5347000 00:02.940.969 832.00 KB
0x52d3000 00:02.998.823 120.00 KB
0x52f1000 00:03.023.068 16.00 KB
これは最初のスタック トレースで、残りは同じです。
0 libsystem_kernel.dylib mach_vm_allocate
1 libsystem_kernel.dylib vm_allocate
2 QuartzCore CA::Render::Shmem::new_shmem(unsigned long)
3 QuartzCore CA::Render::Shmem::new_bitmap(unsigned int, unsigned int, unsigned int, unsigned int)
4 QuartzCore CABackingStoreUpdate_
5 QuartzCore ___ZN2CA5Layer8display_Ev_block_invoke
6 QuartzCore x_blame_allocations
7 QuartzCore CA::Layer::display_()
8 QuartzCore CA::Layer::display_if_needed(CA::Transaction*)
9 QuartzCore CA::Layer::layout_and_display_if_needed(CA::Transaction*)
10 QuartzCore CA::Context::commit_transaction(CA::Transaction*)
11 QuartzCore CA::Transaction::commit()
12 UIKit -[UIApplication _reportAppLaunchFinished]
13 UIKit -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:]
14 UIKit -[UIApplication handleEvent:withNewEvent:]
15 UIKit -[UIApplication sendEvent:]
16 UIKit _UIApplicationHandleEvent
17 GraphicsServices _PurpleEventCallback
18 GraphicsServices PurpleEventCallback
19 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__
20 CoreFoundation __CFRunLoopDoSource1
21 CoreFoundation __CFRunLoopRun
22 CoreFoundation CFRunLoopRunSpecific
23 CoreFoundation CFRunLoopRunInMode
24 UIKit -[UIApplication _run]
25 UIKit UIApplicationMain
26 main
27 libdyld.dylib start
解決
どうやってこれを減らすことができたかを共有したいと思いました。単語が折り返されるラベルがあり、側面と上下にかなりの量の空きスペースがある場合、ラベルを表示するために必要なメモリが増加することがわかります。したがって、解決策は、そのスペースを最小限に抑えることです。
結果のスナップショットは次のとおりです。
Snapshot Timestamp Growth # Persistent
VM: UILabel (CALayer) 2.37 MB 9
0x5321000 00:02.503.255 208.00 KB
0x5248000 00:02.474.045 392.00 KB
0x5087000 00:02.432.317 208.00 KB
0x50bb000 00:02.445.927 64.00 KB
0x5303000 00:02.498.137 120.00 KB
0x52aa000 00:02.481.354 292.00 KB
0x50cb000 00:02.449.625 180.00 KB
0x5355000 00:02.505.638 112.00 KB
0x50f9000 00:02.455.350 848.00 KB