どのnsnotificationがDealloc-edオブザーバーのためにクラッシュしているかを判断する方法
質問
使用の黄金律 NSNotification
と思われる
"電話
removeObserver
の前にobserver
(またはobject
)取引されます」。
私はこのルールが守られていないコードベースを扱っていますが、違反を見つけることはできません。コードを検索し、すべてを確認しました addObserver
マッチングがあります removeObserver
しかし、私はまだ次の品種のクラッシュレポートを見ています:
OS Version: iPhone OS 5.0.1 (9A405)
Report Version: 104
Exception Type: SIGSEGV
Exception Codes: SEGV_ACCERR at 0x8
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x31516fbc objc_msgSend + 16
1 Foundation 0x3195b50f __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_0 + 19
2 CoreFoundation 0x37a02577 ___CFXNotificationPost_block_invoke_0 + 71
3 CoreFoundation 0x3798e0cf _CFXNotificationPost + 1407
4 Foundation 0x318cf3fb -[NSNotificationCenter postNotificationName:object:userInfo:] + 67
5 UIKit 0x34e5ee25 -[UIApplication _handleApplicationSuspend:eventInfo:] + 697
6 UIKit 0x34deed17 -[UIApplication handleEvent:withNewEvent:] + 2031
7 UIKit 0x34dee3bf -[UIApplication sendEvent:] + 55
8 UIKit 0x34dedd2d _UIApplicationHandleEvent + 5809
9 GraphicsServices 0x3750bdf3 PurpleEventCallback + 883
10 CoreFoundation 0x37a0a553 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 39
11 CoreFoundation 0x37a0a4f5 __CFRunLoopDoSource1 + 141
12 CoreFoundation 0x37a09343 __CFRunLoopRun + 1371
13 CoreFoundation 0x3798c4dd CFRunLoopRunSpecific + 301
14 CoreFoundation 0x3798c3a5 CFRunLoopRunInMode + 105
15 GraphicsServices 0x3750afcd GSEventRunModal + 157
16 UIKit 0x34e1c743 UIApplicationMain + 1091
17 App 0x00002d2f main (main.m:14)
このクラッシュレポートの私の解釈はそれです [UIApplication _handleApplicationSuspend:eventInfo:]
削除される前にオブザーバーが扱われている通知を投稿しています。
この解釈が正しいと仮定すると、 どの通知が投稿されているかを判断するにはどうすればよいですか?そして理想的には、オブジェクトタイプは何ですか?
解決
シンボリックブレークポイントを設定できます -[NSNotificationCenter postNotificationName:object:userInfo:]
そして、それに渡された3番目の引数を印刷します(最初の引数は NSNotificationCenter
, 、 二番目、 _cmd
)デバッガーの使用 po
指図。
他のヒント
これを決定する別の方法は、名前パラメーター値(通知を投稿するために渡された文字列)を取得し、文字列/名前がオブジェクトのライフサイクルのいつか、または扱いを受けているときに観測を削除するように設定されていることを観察しているオブジェクトを確認することです。
所属していません StackOverflow