0
votes

[First, please note I'm not using Interface Builder]

I have a NSWindow being shown as a modal sheet when a menu item gets clicked. Here's the code displaying it :

let win = NSWindow(contentRect: NSRect(origin: NSZeroPoint, size: NSSize(width: 650, height: 400)), styleMask: NSResizableWindowMask, backing: .Nonretained, defer: false)
win.releasedWhenClosed = true
setupController = SetupSheetController(window: win)
mainWindow.beginSheet((setupController!.window)!) { (response: NSModalResponse) in
    print("didClose")
    self.setupController = nil
}

setupController being defined as an instance variable var setupController: SetupSheetController?; and SetupSheetController being a NSWindowController subclass.

At the time the user is done with this sheet, self.window?.sheetParent?.endSheet(self.window!, returnCode: NSModalResponseXXX) gets called by the setupController.

My issue being that neither the modal NSWindow nor its controller are getting released. And they're not reused when I reopen the modal sheet, either. Please also note that I'm not referencing the controller at any other place other than shown here. Ideas ?

1

1 Answers

0
votes

OK... Turns out I had to nil out the window itself, although using some indirection : win.windowController?.window = nil (to be written in the beginSheet's completionHandler).

But it doesn't look very elegant to me. Is there any other way ?