macos EXC_BAD_ACCESS (code=1, address=0x0) 当 runModalForWindow

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11064712/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 09:15:45  来源:igfitidea点击:

EXC_BAD_ACCESS (code=1, address=0x0) when runModalForWindow

objective-cmacosexc-bad-access

提问by Radu Paise

I have a window and a window controller which opens when the user clicks a button. Sometimes I get EXC_BAD_ACCESS(code=1, address=0x0).

我有一个窗口和一个窗口控制器,当用户单击按钮时它会打开。有时我会得到 EXC_BAD_ACCESS(code=1, address=0x0)。

0x7fff6f2a59e0:  movq   (%rax), %rdi

Here is the code:

这是代码:

    ChooseProceduresWindowController *chooseProceduresWindowController = [[ChooseProceduresWindowController alloc] initWithWindowNibName:@"ChooseProceduresWindow"];
    [NSApp runModalForWindow:[chooseProceduresWindowController window]];

The error appears then runModalForWindow: is called. I don't get this error every time, but I couldn't find a pattern.

错误出现然后 runModalForWindow: 被调用。我不是每次都收到这个错误,但我找不到模式。

Thanks

谢谢

回答by Tibor Udvari

the best way to debug EXC_BAD_ACCESSerrors is to use NSZombies.

调试EXC_BAD_ACCESS错误的最佳方法是使用NSZombies.

Check out this video for an explanation :

查看此视频以获取解释:

http://youtu.be/LQtPr8bkB3g

http://youtu.be/LQtPr8bkB3g

NSZombiekeeps all your objects in memory when you are trying to release an object that has already been released, so you get closer to finding your bug. As @Mark H said, it is a memory management issue.

NSZombie当您尝试释放已释放的对象时,将所有对象保留在内存中,以便您更接近于找到错误。正如@Mark H 所说,这是一个内存管理问题。

Also you could put an NSLogin your dealloc method to have a better idea of what is getting deallocated when at runtime.

你也可以NSLog在你的 dealloc 方法中放置一个,以便更好地了解在运行时释放的内容。

回答by Mark H

That error will be thrown when the object doesn't exist in memory. I'd start looking for memory management issues. The first would be to make sure you are releasing the ChooseProceduresWindowController after using it.

当对象在内存中不存在时,将抛出该错误。我会开始寻找内存管理问题。首先是确保您在使用之后释放了 ChooseProceduresWindowController。