Skip to content

fix: prevent orphan leak in SetContentView - #52092

Merged
MarshallOfSound merged 1 commit into
electron:mainfrom
gostoshbs:fix/native_window_view_leak
Aug 17, 2026
Merged

MarshallOfSound merged 1 commit into
electron:mainfrom
gostoshbs:fix/native_window_view_leak

Conversation

@gostoshbs

Copy link
Copy Markdown
Contributor

Description of Change

SetContentView detached the previous content view with RemoveChildView, which removes it from the view hierarchy without destroying it. For views Electron owns (not owned_by_client), this leaked the view on every replacement.

Use RemoveChildViewT to delete views we own, keep RemoveChildView for client owned views that must outlive removal, and clear content_view_/focused_view_ before removal so neither references a destroyed view.

Ref #21586.

Checklist

Release Notes

Notes: Fixed a memory leak when creating BrowserWindows.

@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Jun 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ This PR contains unsigned commits. This repository enforces commit signatures
for all incoming PRs. To get your PR merged, please sign those commits
(git rebase --exec 'git commit -S --amend --no-edit -n' @{upstream}) and force push them to this branch
(git push --force-with-lease)

For more information on signing commits, see GitHub's documentation on Telling Git about your signing key.

@github-actions github-actions Bot added the needs-signed-commits Currently some or all of the commits in this PR are not signed label Jun 22, 2026
@electron-datadog

This comment has been minimized.

@gostoshbs
gostoshbs force-pushed the fix/native_window_view_leak branch from 266cd38 to b8e69f9 Compare June 22, 2026 18:45
@github-actions github-actions Bot removed the needs-signed-commits Currently some or all of the commits in this PR are not signed label Jun 22, 2026
@nikwen

nikwen commented Jun 23, 2026

Copy link
Copy Markdown
Member

Related issue for anyone viewing the PR: #48565

(Definitely not necessary to implement this in this PR!)

@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Jun 29, 2026

@ckerr ckerr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The fix LGTM, thanks for the PR!

It looks like native_window_mac.mm:374 has the same issue. @gostoshbs could you fix it there too? Looks to me like the fix would be the same, minus the focused_view_ = nullptr; since the mac code doesn't have that field

@ckerr ckerr added semver/patch backwards-compatible bug fixes target/42-x-y PR should also be added to the "42-x-y" branch. target/43-x-y PR should also be added to the "43-x-y" branch. labels Jun 29, 2026
@gostoshbs
gostoshbs force-pushed the fix/native_window_view_leak branch from b8e69f9 to a281839 Compare June 30, 2026 21:00
@gostoshbs

Copy link
Copy Markdown
Contributor Author

Thanks for having a look. I've pushed the macos equivalent based on your suggestions. One disclaimer, I do not have the capability to build or run the same tests on this platform as I do linux

@github-actions github-actions Bot added the target/44-x-y PR should also be added to the "44-x-y" branch. label Jul 1, 2026
@mlaurencin

Copy link
Copy Markdown
Member

@gostoshbs Can you rebase your branch on main? That should restart the skipped tests

@gostoshbs
gostoshbs force-pushed the fix/native_window_view_leak branch from a281839 to add5476 Compare August 7, 2026 17:45
@github-actions github-actions Bot added the needs-signed-commits Currently some or all of the commits in this PR are not signed label Aug 7, 2026
@gostoshbs
gostoshbs force-pushed the fix/native_window_view_leak branch from add5476 to e78466d Compare August 7, 2026 17:50
@github-actions github-actions Bot removed the needs-signed-commits Currently some or all of the commits in this PR are not signed label Aug 7, 2026
@MarshallOfSound

Copy link
Copy Markdown
Member

Heads up: Windows CI builds moved to new runners on Monday and the old ones have now been removed. This branch predates that, so its Windows build jobs still point at the old runners and will sit queued forever if CI runs again. Rebasing on main (or "Update branch") picks up the change, nothing else needed.

SetContentView detached the previous content view with RemoveChildView,
which removes it from the view hierarchy without destroying it. For
views Electron owns (not owned_by_client), this leaked the view on
every replacement.

Use RemoveChildViewT to delete views we own, keep RemoveChildView for
client owned views that must outlive removal, and clear
content_view_/focused_view_ before removal so neither references a
destroyed view.
@gostoshbs
gostoshbs force-pushed the fix/native_window_view_leak branch from e78466d to e0cddd6 Compare August 13, 2026 11:11
@MarshallOfSound
MarshallOfSound merged commit 86b094b into electron:main Aug 17, 2026
14 checks passed
@welcome

welcome Bot commented Aug 17, 2026

Copy link
Copy Markdown

Congrats on merging your first pull request! 🎉🎉🎉

@release-clerk

release-clerk Bot commented Aug 17, 2026

Copy link
Copy Markdown

Release Notes Persisted

Fixed a memory leak when creating BrowserWindows.

@trop

trop Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "43-x-y", please check out #52892

@trop

trop Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "42-x-y", please check out #52893

@trop trop Bot removed the target/43-x-y PR should also be added to the "43-x-y" branch. label Aug 17, 2026
@trop

trop Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "44-x-y", please check out #52894

@trop trop Bot added in-flight/42-x-y in-flight/44-x-y merged/42-x-y PR was merged to the "42-x-y" branch. merged/44-x-y PR was merged to the "44-x-y" branch. merged/43-x-y PR was merged to the "43-x-y" branch. and removed target/42-x-y PR should also be added to the "42-x-y" branch. target/44-x-y PR should also be added to the "44-x-y" branch. in-flight/42-x-y in-flight/44-x-y in-flight/43-x-y labels Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

45-x-y merged/42-x-y PR was merged to the "42-x-y" branch. merged/43-x-y PR was merged to the "43-x-y" branch. merged/44-x-y PR was merged to the "44-x-y" branch. semver/patch backwards-compatible bug fixes

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

5 participants