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(computed): destroy helper vm of computed to prevent memleak (fix #270) #277

Merged
merged 1 commit into from
Jun 6, 2020

Conversation

LinusBorg
Copy link
Member

@LinusBorg LinusBorg commented Mar 9, 2020

We use a Vue instancefor each computed(), as a helper to actually use Vue's computed: option.

However we don't destroy it when the host component is destroyed. When the computed property references reactive state that's external to the host instance, the helper instance stays in memory as it's watching the external state.

Properly destroying witht the host component fixes this.

fix #270

upon host component destroy.

avoids a memory leak.

fix #270
@LinusBorg LinusBorg changed the title Fix(computed): destroy helper vm of computed to prevent memleak Fix(computed): destroy helper vm of computed to prevent memleak (fix #270) Mar 9, 2020
@LinusBorg LinusBorg requested review from posva and sodatea March 12, 2020 17:40
posva
posva previously approved these changes Mar 13, 2020
Copy link
Member

@posva posva left a comment

Choose a reason for hiding this comment

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

Tested locally and it does fix the leak.
I was concerned about the vm being destroyed while the computed still being used but it doesn't seem to be an issue 👍

@LinusBorg LinusBorg requested a review from posva March 13, 2020 09:54
@LinusBorg
Copy link
Member Author

As just discussed on Dicsord, this might break stuff in specific cirtumstances. We should not merge this now and do further investigations.

@LinusBorg
Copy link
Member Author

This won't work. It will break any computed refs that are meant to persist after their original component has been destroyed.

Will close and investigate other possible ways.

@LinusBorg
Copy link
Member Author

Reopened, see here: #270 (comment)

@LinusBorg LinusBorg reopened this Apr 29, 2020
@commyfriend
Copy link

It seems this pr has been waiting for a long time to be merged.

@antfu antfu self-assigned this May 31, 2020
@antfu antfu mentioned this pull request Jun 3, 2020
Copy link
Member

@antfu antfu left a comment

Choose a reason for hiding this comment

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

Maybe we can get this merged?

I think shared computed should be declared outside of a vm's lifecycle, so the problem blocking this might not exist. (mentioned in #270 (comment)) Any thoughts?

@LinusBorg
Copy link
Member Author

Yeah I think it's fine as well @antfu

@antfu antfu merged commit 39e99c2 into master Jun 6, 2020
@antfu antfu deleted the issue-270-fix-computed-memleak branch June 7, 2020 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

computed on a shared reactive causes a memory leak
4 participants