与NSWindowController和ARC的奇怪的问题 [英] Weird issue with NSWindowController and ARC

查看:322
本文介绍了与NSWindowController和ARC的奇怪的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这是我面对的一个奇怪的情况:


  • NSWindowController 子类, myMainWindow.xib 中的窗口和 AppDelegate.m 调用 NSWindowController 如下:

  • I've got an NSWindowController subclass, a window in myMainWindow.xib and the AppDelegate.m invoking the NSWindowController like this :

myWindowController* controller = [[myWindowController alloc] initWithWindowNibName:@"myMainWindow"];
[controller showWindow:self];


strong>

Now here's what :


  • 当ARC设置为 NO 时,

  • 当我将ARC设置为 YES 时 - 立即设置它) - 它显示一堆错误:

  • When ARC is set to NO, then the app runs fine and the windows shows up ok, too.
  • When I set ARC to YES - immediately after I set it (and for JUST 1 run) - it shows a bunch of errors :

Feb 17 16:35:45 DrKameleons-iMac。本地MyApp [16903]:
kCGErrorIllegalArgument:_CGSFindSharedWindow:WID 2409 Feb 17
16:35:45 DrKameleons-iMac.local MyApp [16903]:kCGErrorFailure:
设置断点@ CGErrorBreakpoint捕获错误,因为它们是
记录。 Feb 17 16:35:45 DrKameleons-iMac.local MyApp [16903]:
kCGErrorIllegalArgument:CGSOrderFrontConditionally:无效的窗口

Feb 17 16:35:45 DrKameleons-iMac.local MyApp[16903] : kCGErrorIllegalArgument: _CGSFindSharedWindow: WID 2409 Feb 17 16:35:45 DrKameleons-iMac.local MyApp[16903] : kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged. Feb 17 16:35:45 DrKameleons-iMac.local MyApp[16903] : kCGErrorIllegalArgument: CGSOrderFrontConditionally: Invalid window

现在,如果我尝试重新运行应用程序(没有改变任何东西,ARC仍然是ON)窗口仍然不显示。但是没有任何错误。 :S

Now if I try rerunning the app (without changing anything, ARC is still ON) the window still doesn't show up. But there is no error at all. :S

发生了什么事?

提示:


  • 在Mac OS X 10.7.5上运行

  • Xcode版本:4.5.1

推荐答案

当ARC打开时,LOCAL控制器在showWindow调用后立即释放!但由于窗口被延迟,窗口甚至还没有 - 甚至是,它将是'无控制器'_
窗口不保留其控制器:)只有反之亦然

when ARC is on, the LOCAL controller is released right after its showWindow call! but as windows are deferred, the window isn't even there yet -- and even it were, it would be 'controller-less'
the Window does NOT retain its controller :) only vice-versa

修复是记住对控制器的引用直到您的appDelegate被释放/直到您退出

the fix is to remember a reference to the controller Until your appDelegate is deallocated/until you quit

@implementation AppDelegate {
    myWindowController* _controller;
}

...
_controller = [[myWindowController alloc] initWithWindowNibName:@"myMainWindow"];
[_controller showWindow:self];






发生和它只是泄漏! ARC确实添加了一个释放调用(因为它正确地看到控制器不再使用)


your code works without arc because no release of controller happens and it just leaks! ARC does add a release call though (as it correctly sees controller is no longer used)

这篇关于与NSWindowController和ARC的奇怪的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆