I have a NSWindow/Controller that I display modal. It has a "Close" button hooked up to an action like this:
- (IBAction)close:(id)sender
{
[self.window orderOut:sender];
[self.window close];
[[NSApplication sharedApplication] stopModal];
}
From my main window, I display the modal:
- (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]);
}
I open and close the modal a few times, and the output is like this:
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
So, [[[NSApplication sharedApplication] windows] count] only ever increases.
I would expect it to increase and decrease as I open and close the modal window. My application uses ARC. Can someone explain this to me?
Thank you in advance
[window isReleasedWhenClosed]
return? Is the modal showing as a sheet, or a top-level modal popup? – abarnert