Reputation:
Do anybody encounter the crash below?
0 WebKitLegacy 0x000000018f766884 std::__1::unique_ptr<WTF::Function<void ()>, std::__1::default_delete<WTF::Function<void ()> > > WTF::MessageQueue<WTF::Function<void ()> >::waitForMessageFilteredWithTimeout<WTF::MessageQueue<WTF::Function<void ()> >::waitForMessage()::'lambda'(WTF::Function<void ()> const&)>(WTF::MessageQueueWaitResult&, WTF::MessageQueue<WTF::Function<void ()> >::waitForMessage()::'lambda'(WTF::Function<void ()> const&)&&, double) + 192
1 WebKitLegacy 0x000000018f765e68 WebCore::StorageThread::threadEntryPoint() + 68
5 JavaScriptCore 0x000000018dabf35c WTF::threadEntryPoint(void*) + 212
6 JavaScriptCore 0x000000018dabf26c WTF::wtfThreadEntryPoint(void*) + 24
8 libsystem_pthread.dylib 0x0000000188c9f860 __pthread_body + 240
9 libsystem_pthread.dylib 0x0000000188c9f770 __pthread_body
10 libsystem_pthread.dylib 0x0000000188c9cdbc start_wqthread + 0
Upvotes: 3
Views: 1912
Reputation: 109
I have fixed this problem by creating a static UIWebView instance.
+ (void)load {
if ([UIDevice isIOS10]) {
static UIWebView *storageCrashFixWebView = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
storageCrashFixWebView = [[UIWebView alloc] initWithFrame:CGRectZero];
[storageCrashFixWebView loadHTMLString:@"<script>window.localStorage</script>" baseURL:nil];
});
}
}
When i set a Symbolic Breakpoint at std::__1::unique_ptr<WTF::Function<void ()>, std::__1::default_delete<WTF::Function<void ()> > > WTF::MessageQueue<WTF::Function<void ()> >::waitForMessageFilteredWithTimeout<WTF::MessageQueue<WTF::Function<void ()> >::waitForMessage()::'lambda'(WTF::Function<void ()> const&)>(WTF::MessageQueueWaitResult&, WTF::MessageQueue<WTF::Function<void ()> >::waitForMessage()::'lambda'(WTF::Function<void ()> const&)&&, double)
, it would break when the last UIWebView which use localStorage
destroyed.
Upvotes: 0
Reputation:
Finally, I find that this crash is related to localstorage thread. When we call window.localStorage in JavaScript, it triggers webkit to create a localstorage thread and the thread will be destoryed when all the UIWebView instances dealloc. In fact, the localstorage thread will be destoryed later than the UIWebView instance which causes wild pointer crash. So, you can create a UIWebView instance which execute "window.localstorage.setItem(x,x)" and never destory it or you can use WKWebView.
Upvotes: 3
Reputation: 5435
Stop loading webView
and remove delegate
before leaving the view.
Before releasing an instance of UIWebView for which you have set a delegate, you must first set its delegate property to nil. This can be done, in your dealloc method.
Try setting delegate for WebView
to nil
and stop WebView loading in viewWillUnload
method of ViewController:
- (void)viewWillUnload {
[webView setDelegate:nil];
[webView stopLoading];
}
Upvotes: 1