Open onmyway133 opened 5 years ago
Good snippet. Any idea why the window is still being released after setting releasedWhenClosed = false
? The window is not inside a windowController.
Also - even when the window (stored in mainWindow
property) is released and I create a new one mainWindow = createNewMainWindow()
and then try to present it again, the app crashes on EXC_BAD_ACCESS (accessing the released property. This is weird, doesn't the property get overriden with the new window in memory?
Good snippet. Any idea why the window is still being released after setting
releasedWhenClosed = false
? The window is not inside a windowController.Also - even when the window (stored in
mainWindow
property) is released and I create a new onemainWindow = createNewMainWindow()
and then try to present it again, the app crashes on EXC_BAD_ACCESS (accessing the released property. This is weird, doesn't the property get overriden with the new window in memory?
Your NSWindow is released by ARC, which may be irrelevant to releasedWhenClosed
. It seems that this such property has conflicted with ARC in Swift. Always set this to false to avoid app crash.
It seems that this such property has conflicted with ARC in Swift.
You might be right with this. close() seems to both release and also remove the window from the NSApplication.shared.windows list which removes the strong reference and ARC performs another release. Which causes a crash because you cannot release an already released object.
Always set this to false to avoid app crash
If this is really the convention for programmatic windows then I blame Apple for not thoroughly documenting this fact.
The reason is that window is released upon closed if it is not owned by
NSWindowController
, or we can use releasedWhenClosed