【发布时间】:2013-03-04 10:26:31
【问题描述】:
好的,情况有点复杂,但对于比我更熟悉 Cocoa 内存管理的人来说,问题本身的性质应该很简单。
一些细节:
- 从我的主应用程序中,我正在加载一个“可加载”包(由 NSWindowController 组成)
- 两个项目(主应用程序和“插件”)都支持 ARC
在我的插件代码中,我有一个自定义初始化方法:
- (id)initWithAPI:(id)api
{
pluginWindowController* newPluginWindowController = [super initWithWindowNibName:@"PluginWindow"];
if (newPluginWindowController)
{
[newPluginWindowController setAPI:api];
}
return newPluginWindowController;
}
API 是这样声明的:
@property (unsafe_unretained) id API;
现在,问题来了:
- 我正在使用
initWithAPI:进行初始化,并且正在设置API。 - 当我在
- (void)windowDidLoad:中测试API的值时,它仍然显示得很好。 - 但是:当尝试从另一种方法中执行相同的操作时(实际上是通过在我的插件窗口中单击按钮触发的 IBAction)...尝试获取
[self API]会触发EXC_BAD_ACCESS错误。
我做错了什么?有什么想法吗?
【问题讨论】:
标签: objective-c cocoa automatic-ref-counting nswindowcontroller