Skip to content

Commit 90cdf88

Browse files
committed
fix: release editor closures on destroy and reclaim malloc pages after teardown
1 parent f816242 commit 90cdf88

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

TablePro/Views/Editor/SQLEditorCoordinator.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff 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

TablePro/Views/Main/MainContentView.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff 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) {

0 commit comments

Comments
 (0)