From 3cb197549cf0b6980e5c4cd72f5a48b65c40c353 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 30 Dec 2024 13:43:48 -0800 Subject: [PATCH] macOS: weak self for event monitor to avoid retain cycle for controllers Fixes #3219 We were holding a reference cycle to the base terminal controller. This was preventing the window from ever being fully deallocated. --- .../Sources/Features/Terminal/BaseTerminalController.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/macos/Sources/Features/Terminal/BaseTerminalController.swift b/macos/Sources/Features/Terminal/BaseTerminalController.swift index 54d505db9..01b211730 100644 --- a/macos/Sources/Features/Terminal/BaseTerminalController.swift +++ b/macos/Sources/Features/Terminal/BaseTerminalController.swift @@ -111,8 +111,8 @@ class BaseTerminalController: NSWindowController, // Listen for local events that we need to know of outside of // single surface handlers. self.eventMonitor = NSEvent.addLocalMonitorForEvents( - matching: [.flagsChanged], - handler: localEventHandler) + matching: [.flagsChanged] + ) { [weak self] event in self?.localEventHandler(event) } } deinit { @@ -160,7 +160,7 @@ class BaseTerminalController: NSWindowController, } // MARK: Notifications - + @objc private func didChangeScreenParametersNotification(_ notification: Notification) { // If we have a window that is visible and it is outside the bounds of the // screen then we clamp it back to within the screen.