Skip to content

fix: prevent orphan leak in SetContentView#52092

Open
gostoshbs wants to merge 1 commit into
electron:mainfrom
gostoshbs:fix/native_window_view_leak
Open

fix: prevent orphan leak in SetContentView#52092
gostoshbs wants to merge 1 commit into
electron:mainfrom
gostoshbs:fix/native_window_view_leak

Conversation

@gostoshbs

Copy link
Copy Markdown

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.

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 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!)

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

Labels

new-pr 🌱 PR opened recently

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants