File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -146,8 +146,21 @@ final class SQLEditorCoordinator: TextViewCoordinator {
146146 inlineSuggestionManager? . uninstall ( )
147147 inlineSuggestionManager = nil
148148
149+ // Release closure captures to break potential retain cycles
150+ onCloseTab = nil
151+ onExecuteQuery = nil
152+ onAIExplain = nil
153+ onAIOptimize = nil
154+ onSaveAsFavorite = nil
155+ schemaProvider = nil
156+ contextMenu = nil
157+ vimEngine = nil
158+ vimCursorManager = nil
159+
149160 EditorEventRouter . shared. unregister ( self )
150161 cleanupMonitors ( )
162+
163+ Self . logger. debug ( " SQLEditorCoordinator destroyed " )
151164 }
152165
153166 // MARK: - AI Context Menu
Original file line number Diff line number Diff line change @@ -272,7 +272,11 @@ struct MainContentView: View {
272272 // If no more windows for this connection, disconnect.
273273 // Tab state is NOT cleared here — it's preserved for next reconnect.
274274 // Only handleTabsChange(count=0) clears state (user explicitly closed all tabs).
275- guard !WindowLifecycleMonitor. shared. hasWindows ( for: connectionId) else { return }
275+ guard !WindowLifecycleMonitor. shared. hasWindows ( for: connectionId) else {
276+ // Hint malloc to return freed pages to the OS
277+ malloc_zone_pressure_relief ( nil , 0 )
278+ return
279+ }
276280
277281 let hasVisibleWindow = NSApp . windows. contains { window in
278282 window. isVisible && ( window. subtitle == connectionName
@@ -281,6 +285,11 @@ struct MainContentView: View {
281285 if !hasVisibleWindow {
282286 await DatabaseManager . shared. disconnectSession ( connectionId)
283287 }
288+
289+ // Give SwiftUI/AppKit time to deallocate view hierarchies,
290+ // then hint malloc to return freed pages to the OS
291+ try ? await Task . sleep ( for: . seconds( 2 ) )
292+ malloc_zone_pressure_relief ( nil , 0 )
284293 }
285294 }
286295 . onChange ( of: pendingChangeTrigger) {
You can’t perform that action at this time.
0 commit comments