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(store-devtools): resolve memory leak when devtools are destroyed #3965

Merged
merged 1 commit into from Jul 23, 2023

Conversation

arturovt
Copy link
Contributor

This commit updates the implementation of the StoreDevtools and adds the ngOnDestroy hook, which ensures the teardown of internal subscriptions. Previously, this caused an excessive memory leak because subscription callbacks created closures that captured this, preventing this from being garbage collected.

@netlify
Copy link

netlify bot commented Jul 22, 2023

Deploy Preview for ngrx-io canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit b8d85a3
🔍 Latest deploy log https://app.netlify.com/sites/ngrx-io/deploys/64bc2fc13aae730008cbbdd5

@arturovt
Copy link
Contributor Author

The failing CIrcle is unrelated since it fails to install the Chrome driver.

@brandonroberts
Copy link
Member

Thanks @arturovt. I pushed up a fix for CI to run the browser tests correctly.

Comment on lines -124 to -125
this.extensionStartSubscription = extensionStartSubscription;
this.stateSubscription = liftedStateSubscription;
Copy link
Member

Choose a reason for hiding this comment

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

For reference, why not just unsubscribe from these in the ngOnDestroy instead of adding a destroy Subject?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, my VSCode initially marked them as unused, so I removed them first. Then I added takeUntil since I saw it's already being used in other places too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can revert properties back and unsubscribe.

Copy link
Member

Choose a reason for hiding this comment

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

I think that approach would be better in this case because the subscription references are already there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

This commit updates the implementation of the `StoreDevtools` and adds the
`ngOnDestroy` hook, which ensures the teardown of internal subscriptions. Previously,
this caused an excessive memory leak because subscription callbacks created closures
that captured `this`, preventing `this` from being garbage collected.
@brandonroberts brandonroberts changed the title fix(store-devtools): resolve leak in StoreDevtools fix(store-devtools): resolve leak when devtools are destroyed Jul 23, 2023
@brandonroberts brandonroberts changed the title fix(store-devtools): resolve leak when devtools are destroyed fix(store-devtools): resolve memory leak when devtools are destroyed Jul 23, 2023
@brandonroberts brandonroberts merged commit 644f0b6 into ngrx:main Jul 23, 2023
6 checks passed
@arturovt arturovt deleted the fix/store-devtools-leak branch July 23, 2023 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants