当我调用NSTimer - [invalidate]方法并将timer设置为nil时,导致carsh。我初始化NSTimer和调用的线程 - [invalidate]方法是同一个线程。但它有时会崩溃。为什么?访问崩溃?这是崩溃日志:
#0. Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x1819d4430 objc_msgSend + 16
1 MTXX 0x100d73480 -[MTBDummyWebViewViewController resetTimerAndAnimation] (MTBDummyWebViewViewController.m:135)
2 MTXX 0x100d73828 -[MTBDummyWebViewViewController webView:shouldStartLoadWithRequest:navigationType:] (MTBDummyWebViewViewController.m:176)
3 UIKit 0x18bda4f9c -[UIWebView webView:decidePolicyForNavigationAction:request:frame:decisionListener:] + 300
4 CoreFoundation 0x182779670 __invoking___ + 144
5 CoreFoundation 0x1826586cc -[NSInvocation invoke] + 292
6 CoreFoundation 0x18265d16c -[NSInvocation invokeWithTarget:] + 60
7 WebKitLegacy 0x18b811858 -[_WebSafeForwarder forwardInvocation:] + 156
8 CoreFoundation 0x1827773bc ___forwarding___ + 624
9 CoreFoundation 0x18265d01c _CF_forwarding_prep_0 + 92
10 CoreFoundation 0x182779670 __invoking___ + 144
11 CoreFoundation 0x1826586cc -[NSInvocation invoke] + 292
12 WebCore 0x18a4d34f4 HandleDelegateSource(void*) + 108
13 CoreFoundation 0x18271a2e8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
14 CoreFoundation 0x18271a268 __CFRunLoopDoSource0 + 88
15 CoreFoundation 0x182719af0 __CFRunLoopDoSources0 + 204
16 CoreFoundation 0x1827176c8 __CFRunLoopRun + 1048
17 CoreFoundation 0x182637fb8 CFRunLoopRunSpecific + 436
18 GraphicsServices 0x1844cff84 GSEventRunModal + 100
19 UIKit 0x18bc0c2e8 UIApplicationMain + 208
20 MTXX 0x10047f6bc main (main.m:15)
21 libdyld.dylib 0x18215a56c start + 4
--
它们的用法如下:
[self.timeoutTimer invalidate];
self.timeoutTimer = nil;