diff --git a/macos/Sources/Features/Primary Window/PrimaryWindowController.swift b/macos/Sources/Features/Primary Window/PrimaryWindowController.swift index a77aebf28..bd85972fc 100644 --- a/macos/Sources/Features/Primary Window/PrimaryWindowController.swift +++ b/macos/Sources/Features/Primary Window/PrimaryWindowController.swift @@ -11,4 +11,14 @@ class PrimaryWindowController: NSWindowController { guard let manager = self.windowManager else { return } manager.triggerNewTab(for: window) } + + deinit { + // I don't know if this is the right place, but because of WindowAccessor in our + // SwiftUI hierarchy, we have a reference cycle between view and window and windows + // are never freed. When the window is closed, the window controller is deinitialized, + // so we can use this opportunity detach the view from the window and break the cycle. + if let window = self.window { + window.contentView = nil + } + } }