简体   繁体   English

在可可应用程序中关闭文档时崩溃

[英]Crash when closing document in cocoa app

I have a document based cocoa app where each document is a web view. 我有一个基于文档的可可应用程序,其中每个文档都是一个Web视图。

Sometime when I close a document it crashes. 有时,当我关闭文档时,它崩溃了。 Running Zombies it says An Objective-C message was sent to a deallocated 'MyDocument' object (zombie) when the crash happens. 运行Zombies时说崩溃发生时, An Objective-C message was sent to a deallocated 'MyDocument' object (zombie)

It says the responsible caller is -[NSDocumentController makeUntitledDocumentOfType:error:] . 它说负责的呼叫者是-[NSDocumentController makeUntitledDocumentOfType:error:]

I don't understand why this method would be getting called after I close a document. 我不明白为什么在关闭文档后会调用此方法。

I finally found the solution after some help using a technical support incident with Apple. 经过使用苹果技术支持事件的帮助后,我终于找到了解决方案。

I had to nil out the ui delegate in my -dealloc. 我必须在-dealloc中取消ui委托。 Everything works fine now. 现在一切正常。

- (void)dealloc
{
    [self.webView setUIDelegate:nil];
}

The engineer told me for compatibility reasons even when using ARC most objects still have to use __unsafe_unretained references for their delegates instead of __weak . 出于兼容性原因,工程师告诉我,即使使用ARC时,大多数对象仍必须为其委托使用__unsafe_unretained引用而不是__weak

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM