2011-05-06 54 views
1

我看到偶爾崩潰報告中_WebTryThreadLock這樣的:WebTryThreadLock SEGV

Exception Type: SIGSEGV 
    Exception Codes: SEGV_ACCERR at 0xffffffffbbadbeef 

    Thread 5 Crashed: 
0 WebCore        0x00005822 _WebTryThreadLock(bool) + 158 
1 WebCore        0x0000576f WebThreadLock + 47 
2 UIKit        0x001ae019 -[UIWebView dealloc] + 73 
3 CoreFoundation      0x00006f7b -[NSObject(NSObject) release] + 31 
4 Foo         0x0000c001 -[FooViewController dealloc] (FooViewController.m:653) 
5 CoreFoundation      0x00006f7b -[NSObject(NSObject) release] + 31 
6 CoreFoundation      0x0000b3c9 CFRelease + 69 
7 CoreFoundation      0x0000a8df _CFAutoreleasePoolPop + 147 
8 libSystem.B.dylib     0x000d6c04 _dispatch_worker_thread2 + 228 
9 libSystem.B.dylib     0x0007b251 _pthread_wqthread + 265 

Thread 1 Crashed: 
0 WebCore        0x34c263c8 _WebTryThreadLock(bool) + 112 
1 WebCore        0x34c281b1 WebThreadLock + 53 
2 UIKit        0x35a3765f -[UITextView dealloc] + 31 
3 CoreFoundation      0x30329c43 -[NSObject(NSObject) release] + 31 
4 UIKit        0x358ad5f5 -[UIView(Hierarchy) removeFromSuperview] + 365 
5 UIKit        0x359426cd -[UIScrollView removeFromSuperview] + 49 
6 UIKit        0x35a352f1 -[UITextView removeFromSuperview] + 73 
7 UIKit        0x358c0de3 -[UIView dealloc] + 155 
8 CoreFoundation      0x30329c43 -[NSObject(NSObject) release] + 31 
9 UIKit        0x3591900f -[UIViewController dealloc] + 175 
10 Foo         0x0000c167 -[FooViewController dealloc] (FooViewController.m:646) 
11 CoreFoundation      0x30329c43 -[NSObject(NSObject) release] + 31 
12 CoreFoundation      0x3032a1a1 CFRelease + 69 
13 CoreFoundation      0x3032cebb _CFAutoreleasePoolPop + 147 
14 libdispatch.dylib     0x33d0b6a5 _dispatch_worker_thread2 + 373 
15 libsystem_c.dylib     0x33e0a591 _pthread_wqthread + 265 

我無法重現這在我自己的測試雖然,所以我不肯定是什麼觸發它。它絕對不會經常發生。當我嘗試修改主線程以外的線程的UIKit元素時,我已經在WebThreadLock中看到了崩潰的提及。

我認爲必須是這裏發生的事情,因爲_dispatch_worker_thread2告訴我這是GCD線程與UIApplicationMain線程之一。我必須在GCD線程上運行一些東西,在主線程放開它後保持FooViewController的狀態,我想在這個非主線程中發生的removeFromSuperview調用是觸發問題的原因。

回答

2

我想通了這一點得益於Rentzsch的發佈/保留調試提示這裏:

http://rentzsch.tumblr.com/post/3895140826/retain-release-debugging

的問題,我從一個GCD線程,這是造成該線程作出[UINavigationController的visibleViewController]通話呼籲保留在我的FooViewController:

0 Foo         0x00009d98 -[FooViewController retain] + 216 
1 UIKit        0x0049e5ad -[UINavigationController topViewController] + 61 
2 UIKit        0x0049e4ca -[UINavigationController visibleViewController] + 133 
3 Foo         0x0003c0bd -[BarViewController updateStatus:animated:] + 147 
4 Foo         0x0003799e -[BarViewController reallyProcessMetadata] + 229 
5 Foo         0x0003650e __39-[BarViewController processMetadata]_block_invoke_0828 + 408 
6 libdispatch_sim.dylib    0x01a63289 _dispatch_call_block_and_release + 16 
7 libdispatch_sim.dylib    0x01a6658a _dispatch_worker_thread2 + 252 
8 libSystem.B.dylib     0x98d2bd21 _pthread_wqthread + 390 
9 libSystem.B.dylib     0x98d2bb66 start_wqthread + 30 

當線程的自動釋放池,水渠,這是最後的傢伙拿着FooViewController時,將導致崩潰。如果你足夠幸運到在調試程序重現此,你會在控制檯中看到這一點:

2011-05-06 19:34:40.651 Foo[59365:943b] bool _WebTryThreadLock(bool), 0x11393b30: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now... 
Program received signal: 「EXC_BAD_ACCESS」. 

所以在我的情況的解決方案是不是從這個線程使用visibleViewController。我以前只是調用[UINavigationController viewControllers]並檢查我的控制器是否是最後一個對象,並且從未崩潰。

相關問題