Skip to content

Conversation

Hbbbit
Copy link
Contributor

@Hbbbit Hbbbit commented Jul 11, 2025

What it does
Fixes a memory leak in @theia/core/lib/browser/browser-menu-plugin.ts caused by inconsistent usage of addEventListener and removeEventListener.
Previously, an event listener was registered with capture: true, but removed without specifying the same option.
This mismatch prevented the listener from being properly removed, leading to retained memory on repeated context menu interactions.

This change ensures that both addEventListener and removeEventListener use the same options, allowing proper cleanup and stable memory usage.

Fixes #15975

How to test
Launch Theia and open the browser developer tools (e.g., Chrome DevTools).

Right-click anywhere in the Theia UI to open the context menu, then click elsewhere to close it.

Repeat the open/close operation ~10 times.

Take two memory snapshots before and after.
You should now see that no redundant event listeners remain and memory usage stays stable.

Without the fix, you would observe increasing retained nodes in memory.

Follow-ups
None currently.
Could consider writing automated regression tests if event listener state becomes more observable in future refactoring.

Breaking changes
This PR does not introduce breaking changes.

Attribution
Contributed by Hbb.

@github-project-automation github-project-automation bot moved this to Waiting on reviewers in PR Backlog Jul 11, 2025
@sdirix
Copy link
Member

sdirix commented Jul 11, 2025

Hi! Thanks for the contribution ❤️

Please make sure to sign the ECA, otherwise this can't be merged. Thanks!

@Hbbbit Hbbbit changed the title fix: DynamicMenuWidget Memory Leak #15975 fix: DynamicMenuWidget Memory Leak #15975 Jul 14, 2025
@Hbbbit
Copy link
Contributor Author

Hbbbit commented Jul 14, 2025

DONE

Copy link
Member

@sdirix sdirix left a comment

Choose a reason for hiding this comment

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

I can confirm that the pointerdown event listeners are successfully cleaned up with this PR

@github-project-automation github-project-automation bot moved this from Waiting on reviewers to Needs merge in PR Backlog Jul 20, 2025
@sdirix sdirix merged commit cf30b9d into eclipse-theia:master Jul 20, 2025
10 of 11 checks passed
@github-project-automation github-project-automation bot moved this from Needs merge to Done in PR Backlog Jul 20, 2025
@github-actions github-actions bot added this to the 1.64.0 milestone Jul 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

DynamicMenuWidget Memory Leak
2 participants