Repository navigation
Free the Settings window when it closes - #1930
Conversation
The Settings window controller was created once and kept for the life of the app, so every tab's SwiftUI and AppKit views stayed in memory after the window was closed. Drop the window content after close and clear the reference; the next open builds a fresh window. Measured on macOS 26.6, Release build, all four tabs visited, then closed: live heap 36 MB -> 14.6 MB, footprint 64 MB -> 55 MB. Idle at launch is unchanged at 12 MB.
|
Thanks! I've been meaning to do this. One thing that I've been doing in my other apps is saving which tab it was open on, and navigating back to that tab when it opens. Would you be up for adding that in as part of this PR? |
Save the selected Settings tab in UserDefaults when the user switches tabs and select it again when the window is built, so closing or relaunching lands back on the same tab instead of always on Shortcuts. The window title and initial size follow the restored tab, measured from the tab view that is already built rather than a throwaway one. An unknown saved value falls back to Shortcuts. The key is UI state, so it is left out of settings export.
|
Sure, it's done. Settings now remembers which tab was open and goes back to it the next time the window opens, including after quitting the app. The window title and size follow that tab, and if the saved value isn't a valid tab it falls back to Shortcuts. I kept it out of the settings export since it's window state rather than a preference. |
|
Thanks! There's a bug with sizing the different tabs when reopening that's exposed by saving and restoring the tab, but I have a fix for it and I'll just commit it to this branch and merge it when I have it done. |
…b sizes; also removed persistence between app restarts
|
I ended up removing the persistence across app relaunches, as I preferred starting consistently at the shortcuts tab. Thanks again! |
Brings in v2.0.4 and the 19 commits after it. The Settings window fix landed upstream as rxhanson#1930 with more on top (remembering the last tab and window size), so SettingsWindowController.swift takes upstream's version. The fork's main now has the same files as upstream's.
Summary
Rectangle created the Settings window once and kept it for the life of the app. After the window was closed, every tab it had shown (the shortcuts outline, the Snap Areas, Behavior and App Settings SwiftUI forms) stayed in memory.
Now
SettingsWindowControlleris the window's delegate. On close it tellsAppDelegateto drop its reference and then clears the window'scontentViewController, because AppKit keeps a closed window alive. The next open builds a fresh window.Measurements
macOS 26.6, Apple Silicon, Release build. Settings opened, all four tabs visited, closed; repeated 3 times.
SettingsTabViewControlleralive after closeRepeating open and close doesn't grow memory in either build.
What this does not change
Test plan
heapandfootprintBuilt and tested on macOS 26.6 with Xcode 26.6. To compile with that SDK I stubbed out the macOS 27-only lines locally (the app icon and
preferredImageVisibility); those local changes are not part of this PR.