Skip to content

Fix WindowRoot memory leak in SUI#19826

Merged
carlos-zamora merged 3 commits intomainfrom
dev/cazamor/bugfix/window-root-memory-leak
Feb 3, 2026
Merged

Fix WindowRoot memory leak in SUI#19826
carlos-zamora merged 3 commits intomainfrom
dev/cazamor/bugfix/window-root-memory-leak

Conversation

@carlos-zamora
Copy link
Member

Summary of the Pull Request

Fixes a memory leak for IHostedInWindow in the TerminalSettingsEditor.

The memory leak occurs from MainPage creating an object that stores reference to back to MainPage as IHostedInWindow. With IconPicker specifically, the cycle would look like MainPage --> NewTabMenu --> IconPicker --> MainPage.

I've audited uses of IHostedInWindow in the TerminalSettingsEditor and replaced them as weak references. I also checked areas that WindowRoot() was called and added a null-check for safety.

Validation Steps Performed

Verified MainPage and NewTabMenu dtors are called when the settings UI closes from...
✅ Launch page (base case - it doesn't have an IHostedInWindow)
✅ New Tab Menu page

_WeakWindowRoot(windowRoot) {}

Editor::IHostedInWindow WindowRoot() const noexcept { return _WindowRoot; }
Editor::IHostedInWindow WindowRoot() const noexcept { return _WeakWindowRoot ? _WeakWindowRoot.get() : nullptr; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in some places you do weak ? weak.get : nullptr, and in others you just do weak.get; why the difference?

(fwiw i think weak.get returns nullptr properly on its own when you'd expect it to)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I tried to make all of them consistent. But if weak.get() already returns nullptr properly, I'll just use that tbh.

const auto list = NewTabMenuListView();
MoveToFolderButton().IsEnabled(list.SelectedItems().Size() > 0);
DeleteMultipleButton().IsEnabled(list.SelectedItems().Size() > 0);
NewTabMenuListView().SelectionChanged([weakThis = get_weak()](auto&&, auto&&) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will the selection conceivably change after this has been destructed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not, this doesn't need to be a weak reference.

Comment on lines -28 to -30
const auto list = NewTabMenuListView();
MoveToFolderButton().IsEnabled(list.SelectedItems().Size() > 0);
DeleteMultipleButton().IsEnabled(list.SelectedItems().Size() > 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code was fine as it was, but I'm not blocking over this change

@carlos-zamora carlos-zamora merged commit 27aae1f into main Feb 3, 2026
18 of 20 checks passed
@carlos-zamora carlos-zamora deleted the dev/cazamor/bugfix/window-root-memory-leak branch February 3, 2026 22:25
DHowett pushed a commit that referenced this pull request Feb 10, 2026
Replaces usage of `NavigateToXArgs` in the `TerminalSettingsEditor` with
`NavigateToPageArgs`. They all did pretty much the same thing anyways.

Refs #19826
Refs #19519
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants