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 a memory leak with the root column tree node #994

Merged
merged 1 commit into from
Jul 30, 2023
Merged

Conversation

mmun
Copy link
Contributor

@mmun mmun commented Jul 30, 2023

This PR fixes a memory leak that due to the root node not being destroyed when its dependency key columns is invalidated.

The reason this leaks memory is because some nodes in the ColumnTree structure add observers, and those observers are stored in a global map. If we don't explicitly destroy them the observers are never removed.

This exact pattern is already in use in this codebase for the CollapseTree: https://github.com/Addepar/ember-table/blob/master/addon/-private/collapse-tree.js#L810-L812

@@ -599,7 +600,10 @@ export default EmberObject.extend({

destroy() {
this.token.cancel();
get(this, 'root').destroy();
Copy link
Member

Choose a reason for hiding this comment

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

Why was this destruction call insufficient?

Copy link
Contributor Author

@mmun mmun Jul 30, 2023

Choose a reason for hiding this comment

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

If the root computed property is invalidated (i.e. columns changes) then old value of root is lost and never destroyed. But yes, it does correctly destroy the current root.

Copy link
Contributor Author

@mmun mmun Jul 30, 2023

Choose a reason for hiding this comment

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

The new code in destroy isn't much different. It just avoids unnecessarily instantiating a root node if it wasn't already computed (and mirrors how the CollapseTree nodes already work).

The main fix in this PR is to add the cleanup logic at the beginning of the root CP computation.

@mixonic
Copy link
Member

mixonic commented Jul 30, 2023

I see it now. Excellent.

@mixonic mixonic merged commit 149472b into master Jul 30, 2023
8 checks passed
@mixonic mixonic deleted the mmun/memory-leak branch July 30, 2023 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants