我遇到了NSWindowController的一個奇怪的情況。我想要釋放窗口控制器,但它不會。它似乎不符合我對ARC行爲的期望。NSWindowController子類不會在ARC中發佈
我創建了一個簡單的窗口控制器的子類,PlainWindowController。它的接口和實現都是空的:
#import <Cocoa/Cocoa.h>
@interface PlainWindowController : NSWindowController
@end
@implementation PlainWindowController
@end
我用它創建一個默認windowController廈門國際銀行名爲PlainWindowController.xib
,它與代表和windowController連接的窗口已經設置。當這個測試運行中,弱引用不是nil
PlainWindowController *strongWindowController = [[PlainWindowController alloc] initWithWindowNibName:@"PlainWindowController"];
__weak PlainWindowController *weakWindowController = strongWindowController;
[strongWindowController showWindow:nil];
strongWindowController = nil;
STAssertNil(weakWindowController, @"The window controller should have been deleted, wasn't");
:
在測試中,我寫了這個代碼。
如果我離開了showWindow
是零。如果我使用init
而不是initWithWindowNibName
,則它是零。
有人知道這裏發生了什麼嗎?提前感謝您的任何指導。
感謝您的澄清。事實上,如果我在常規應用程序的某個地方初始化該筆尖而沒有任何強大的參考,它會在某個未知的時間(但很快)發生dealloc。由ARC提供的新控件仍然被幕後的autoreleases玷污,這太糟糕了。 – stevel