Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak in plugin tree views #12353

Merged
merged 2 commits into from
Apr 12, 2023
Merged

Conversation

pisv
Copy link
Contributor

@pisv pisv commented Mar 27, 2023

Fixes #10404.

What it does

Fixes a bug in TreeViewExtImpl<T>.getChildren(parentId: string), where newly created top-level children were added to the old root node instead of the new one. This caused a memory leak by retaining an implicit reference to the old root node from the new one and failing to properly track and, hence, dispose the top-level children.

The fix ensures that old nodes get disposed and become subject to garbage collection by reusing the single root node instead of creating a new one on full refresh.

See #10404 (comment) for more information.

How to test

Verify that plugin tree views still work as expected, and there is no memory leak on full refresh now.

For example, open Theia on the vscode-extension-samples/helloworld-sample workspace, and use the Node Dependencies view contributed by the vscode-extension-samples/tree-view-sample:

  • Take a heap snapshot using Chrome DevTools and verify that there is exactly six Dependency objects.
  • Refresh the view and take another heap snapshot. Verify that there is still exactly six Dependency objects.

Review checklist

Reminder for reviewers

Fixes a bug in `TreeViewExtImpl<T>.getChildren(parentId: string)`,
where newly created top-level children were added to the old root node
instead of the new one. This caused a memory leak by retaining an implicit
reference to the old root node from the new one and failing to properly track
and, hence, dispose the top-level children.

The fix ensures that old nodes get disposed and become subject to garbage
collection by reusing the single root node instead of creating a new one
on full refresh.

See eclipse-theia#10404 (comment)
for more information.

Fixes eclipse-theia#10404.
@msujew msujew added the tree issues related to the tree (ex: tree widget) label Mar 28, 2023
Copy link
Contributor

@tsmaeder tsmaeder left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@tsmaeder
Copy link
Contributor

I was able to verify that the number of nodes doesn't grow upon refresh.

@tsmaeder tsmaeder merged commit b56f399 into eclipse-theia:master Apr 12, 2023
@tsmaeder
Copy link
Contributor

Thanks for the fix.

@pisv pisv deleted the GH-10404 branch April 12, 2023 10:12
@pisv
Copy link
Contributor Author

pisv commented Apr 12, 2023

Thanks for the review!

@vince-fugnitto vince-fugnitto added this to the 1.37.0 milestone Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tree issues related to the tree (ex: tree widget)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Memory leak in plugin tree views
4 participants