我有一個NSWindow/Controller,顯示模態。它有一個「關閉」按鈕迷上了一個動作是這樣的:NSApplication窗口屬性 - Windows未刪除?
- (IBAction)close:(id)sender
{
[self.window orderOut:sender];
[self.window close];
[[NSApplication sharedApplication] stopModal];
}
從我的主窗口中,我顯示模式:
- (IBAction)modal:(id)sender
{
NSLog(@"Before: %lu", [[[NSApplication sharedApplication] windows] count]);
ModalWindowController *modal = [[ModalWindowController alloc] initWithWindowNibName:@"ModalWindowController"];
[[NSApplication sharedApplication] runModalForWindow:modal.window];
NSLog(@"After: %lu", [[[NSApplication sharedApplication] windows] count]);
}
我打開和關閉模式幾次,和輸出是這樣的:
2013-01-17 14:36:08.071 Modals[3666:303] Before: 1
2013-01-17 14:36:08.962 Modals[3666:303] After: 2
2013-01-17 14:36:09.578 Modals[3666:303] Before: 2
2013-01-17 14:36:11.009 Modals[3666:303] After: 3
2013-01-17 14:36:12.108 Modals[3666:303] Before: 3
2013-01-17 14:36:12.910 Modals[3666:303] After: 4
所以,[[[的NSApplication sharedApplication]窗口]計數]永遠只能增加。
我希望它隨着我打開和關閉模式窗口而增加和減少。我的應用程序使用ARC。誰可以給我解釋一下這個?
預先感謝您
什麼是'[window isReleasedWhenClosed]'return?模式顯示爲表單還是頂級模態彈出窗口? – abarnert
關閉時窗口被設置爲釋放。事實證明,我沒有在這個項目上啓用ARC,因此控制器仍被保留。謝謝! – TheNextman
好的,所以問題是你認爲你使用ARC,但不是?是的,這將導致各種泄漏... – abarnert