OSX 10.10.3在dealloc上崩溃了WebView

时间:2015-04-20 11:03:39

标签: objective-c macos cocoa webview

更新到10.10.3后,WebView组件在dealloc

之后开始崩溃
- (void)dealloc {
    [self.webView.windowScriptObject setValue:nil forKey:@"CocoaApp"];
    [[self.webView mainFrame] stopLoading];
    [self.webView setUIDelegate:nil];
    [self.webView setEditingDelegate:nil];
    [self.webView setFrameLoadDelegate:nil];
    [self.webView setPolicyDelegate:nil];
    [self.webView removeFromSuperview];
}

崩溃发生在WebView的深处

EXC_BAD_ACCESS

1   0x7fff910bae9e WebDocumentLoaderMac::detachFromFrame()
2   0x7fff920288c0 WebCore::FrameLoader::detachFromParent()
3   0x7fff910d0e55 -[WebView(WebPrivate) _close]
4   0x7fff910d0c49 -[WebView dealloc]
5   0x7fff8b1cf89c objc_object::sidetable_release(bool)
6   0x7fff8b1b5e8f (anonymous namespace)::AutoreleasePoolPage::pop(void*)
7   0x7fff912b26f2 _CFAutoreleasePoolPop
8   0x7fff8830e762 -[NSAutoreleasePool drain]
9   0x7fff8e3f0cc1 -[NSApplication run]
10  0x7fff8e36d354 NSApplicationMain
11  0x1000ebb12 main
12  0x7fff8c81e5c9 start
13  0x3

有什么想法吗?这是Apple的bug吗?它开始于10.10.3之后?

启用NSZombie时不会崩溃!

2 个答案:

答案 0 :(得分:1)

我注意到您正在使用自己的政策代表:

decidePolicyForMIMEType:request:frame:decisionListener:

WebKit中存在与策略委托相关的已知错误(仅在最近修复):

https://bugs.webkit.org/show_bug.cgi?id=144975

简短版本是你可能会遇到这个断言(这会使故意的段错误导致进程崩溃):

https://github.com/WebKit/webkit/blob/24b1ae89efc10a4e6a6057b429c8e1d8d138a32f/Source/WebCore/loader/DocumentLoader.cpp#L935

因为您的政策处理程序(即use)未能做出政策决定(即ignoredownloadpublic void deleteContacts(String contactNote){ ContentResolver cr = getContentResolver(); Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); String note; while (cur.moveToNext()) { note = ""; try{ String lookupKey = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY)); String noteWhere = ContactsContract.Contacts.LOOKUP_KEY + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?"; String[] noteWhereParams = new String[]{lookupKey, ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE}; Cursor noteCur = cr.query(ContactsContract.Data.CONTENT_URI, null, noteWhere, noteWhereParams, null); if (noteCur.moveToFirst()) { note = noteCur.getString(noteCur.getColumnIndex(ContactsContract.CommonDataKinds.Note.NOTE)); if(note.equals(contactNote)) { Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey); cr.delete(uri, null, null); } } noteCur.close(); } catch(Exception e) { System.out.println(e.getStackTrace()); } } cur.close(); } )。该决定悬而未决,当加载程序最终分离时,它断言没有待决的策略决策,由于视图仍在等待决策,因此决策失败。

答案 1 :(得分:0)

我做的修复,不是要发布webview,而是保留一个静态引用(这远非解决它,我就此问题与Apple联系)

#warning HOTFIX
{
    //this is because of http://stackoverflow.com/questions/29746074/osx-10-10-3-crashes-webview-on-dealloc
    static NSMutableArray * LIVE_FOR_EVER_WEBVIEW;

    if (LIVE_FOR_EVER_WEBVIEW == nil) {
        LIVE_FOR_EVER_WEBVIEW = [NSMutableArray new];
    }
    if (self.webView) {
        [LIVE_FOR_EVER_WEBVIEW addObject:self.webView];
    }
}