From e9202350388d381a40e07c3a2672b278c7af2117 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Mon, 2 Mar 2020 18:06:55 -0800 Subject: [PATCH] Remove references to windows when they close so that they will deallocate. --- Mac/AppDelegate.swift | 6 ++++++ Mac/MainWindow/MainWindowController.swift | 2 ++ 2 files changed, 8 insertions(+) diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index b7c916272..34b8703cb 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -383,6 +383,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, } } + func removeMainWindow(_ windowController: MainWindowController) { + if let index = mainWindowControllers.firstIndex(of: windowController) { + mainWindowControllers.remove(at: index) + } + } + // MARK: NSUserInterfaceValidations func validateUserInterfaceItem(_ item: NSValidatedUserInterfaceItem) -> Bool { if shuttingDown { diff --git a/Mac/MainWindow/MainWindowController.swift b/Mac/MainWindow/MainWindowController.swift index fe07dd1b9..547200583 100644 --- a/Mac/MainWindow/MainWindowController.swift +++ b/Mac/MainWindow/MainWindowController.swift @@ -462,7 +462,9 @@ extension MainWindowController: NSWindowDelegate { } func windowWillClose(_ notification: Notification) { + // TODO: now that we are deallocating main window controllers, the media playback stop can probably be removed detailViewController?.stopMediaPlayback() + appDelegate.removeMainWindow(self) } }