可可的僵尸事件

发布于 2024-12-19 09:12:38 字数 793 浏览 7 评论 0原文

我遇到 EXC_BAD_ACCESS 错误。我在 xCode 4 中使用Profile来查看内存发生了什么,发现这是僵尸事件:

An Objective-C message was sent to a deallocated object(zombie) at address ... 

我在对象列表中找到了提到的地址。负责任的调用者是

-[NSWindowTemplate nibInstantiate]

僵尸 负责任的调用者 - [NSApplication(NSWindowCache) _checkForTerminateAfterLastWindowClosed: saveWindows:]

在僵尸事件之前有 -[NSWindow _close], [NSWindow keep] 和几个 [NSWindow release] 事件(最后一个 [NSWindow release] 之后引用计数 = 0)

当我关闭应用程序时,发生EXC_BAD_ACCESS。我对所有代码进行了注释,因此启动应用程序后不会执行任何操作。我启动它并立即关闭 - 并引发错误。

为什么_checkForTerminateAfterLastWindowClosed启动,如何防止EXC_BAD_ACCESS?有什么想法吗?

谢谢

I have a EXC_BAD_ACCESS error. I used Profile in xCode 4 to see what is happening with memory and saw that it is zombie event:

An Objective-C message was sent to a deallocated object(zombie) at address ... 

I found mentioned address in Object List. Responsible caller is

-[NSWindowTemplate nibInstantiate]

Zombie Responsible Caller - [NSApplication(NSWindowCache) _checkForTerminateAfterLastWindowClosed: saveWindows:]

Before zombie event there're -[NSWindow _close], [NSWindow retain] and several [NSWindow release] events (Ref count = 0 after last [NSWindow release])

EXC_BAD_ACCESS occurs when I close application. I commented all code so nothing is executing after launching of application. I launch it and immediately close - and error fires.

Why _checkForTerminateAfterLastWindowClosed launch, how to prevent EXC_BAD_ACCESS?Any ideas?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黯然#的苍凉 2024-12-26 09:12:38

我们可以安全地假设调用_checkForTerminateAfterLastWindowClosed来检查应用程序是否应该在其最后一个窗口关闭后终止。我们可以进一步假设它是通过 询问您的应用程序委托

我刚刚在你之前的问题中注意到你的窗口是你的应用程序的委托。所以我猜测是这样的:

EXC_BAD_ACCESS 在我关闭应用程序时发生。

您的意思是当您关闭窗口时会发生这种情况。 (应用程序无法关闭;该动词不与该名词一起使用。您关闭窗口并退出或终止应用程序。)

当您关闭窗口时(假设它是您打开的唯一窗口),应用程序询问其委托是否应该因此退出。不幸的是,您设置为其委托的对象是您刚刚关闭的窗口,因此被杀死。

这就是正在发送消息的死对象(仪器将确认这一点):您的窗口,它也是您的应用程序的委托。

最好的解决方案是将对象拆分为两个(或三个):创建 NSObject 的直接子类,并将其实例作为应用程序的委托,并让其创建并拥有一个加载窗口的窗口控制器。

We can safely assume _checkForTerminateAfterLastWindowClosed is called to check whether the application should terminate after its last window is closed. We can further assume that it does this by asking your application delegate.

I just noticed in your previous question that your window is your application's delegate. So I'm guessing that by:

EXC_BAD_ACCESS occurs when I close application.

you meant that it happens when you close the window. (An application can't be closed; that verb doesn't go with that noun. You close windows and quit, or terminate, applications.)

When you close the window (assuming that it was the only window you had up), the application goes to ask its delegate whether it should quit as a result of that. Unfortunately, the object you set as its delegate is the window that you just closed, and thereby killed off.

So that's the dead object that is being messaged (Instruments will confirm this): Your window, which is also your application's delegate.

The best solution is to split the object in two (or three): Make a direct subclass of NSObject, and an instance of that to be your application's delegate, and have that create and own a window controller, which loads the window.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文