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

Free resources (free detached nodes from memory) #1380

Merged
merged 4 commits into from Aug 18, 2019

Conversation

MosheZemah
Copy link
Contributor

Found an issue when using virtualized list (https://github.com/bvaughn/react-virtualized), where unmounted react components (connected to store using connect) were not collected by the garbage collector.
I'm not sure what is the exact explanation here, but it solved my problem.

Found an issue when using virtualized list (https://github.com/bvaughn/react-virtualized), where unmounted react components (connected to store using connect) were not collected by the garbage collector. 
I'm not sure what is the exact explanation here, but it solved my problem.
@netlify
Copy link

netlify bot commented Aug 15, 2019

Deploy preview for react-redux-docs ready!

Built with commit 8c7001e

https://deploy-preview-1380--react-redux-docs.netlify.com

@markerikson
Copy link
Contributor

markerikson commented Aug 15, 2019

Can you put together a sandbox that shows the problem in action, so that we can check to see if this actually makes any difference?

I don't see any reason why this change would be a problem, I just want to see how much it helps.

Remove comment

Co-Authored-By: Tim Dorr <timdorr@users.noreply.github.com>
@MosheZemah
Copy link
Contributor Author

Can you put together a sandbox that shows the problem in action, so that we can check to see if this actually makes any difference?

I don't see any reason why this change would be a problem, I just want to see how much it helps.

Hi, thanks for replying.
It seems like a specific case with virtualized list, where I scroll up and down and many components are mounting and unmounting (every time they enter/exit the DOM). I'm not sure I'll be able to reproduce it on a sandbox. Is there any possibility that "onStateChange" which holds reference to checkForUpdates somehow retain a reference to the component which keeps it from being garbage collected? I can add a screenshot where I have allot of Detached div elements, and I've traced them down to their holder - "Subscription" (forcing GC didn't free them). After applying my change, the problem seems to be solved.

@markerikson
Copy link
Contributor

Well, connect is now a function component, so there's no component reference that can be accessed by app logic.

In theory, what I would expect is:

  • React unmounts the component and cleans up the hooks list
  • No hooks point to the Subscription instance, so it's GC'd
  • Anything the Subscription points to is GC'd

But, all that said, I see no reason why this change would be an issue, so let's get it in.

@markerikson markerikson merged commit b6b4799 into reduxjs:master Aug 18, 2019
@MosheZemah MosheZemah deleted the patch-1 branch August 18, 2019 19:11
webguru7 pushed a commit to webguru7/react-redux that referenced this pull request Dec 8, 2022
* Free resources (free detached nodes from memory)

Found an issue when using virtualized list (https://github.com/bvaughn/react-virtualized), where unmounted react components (connected to store using connect) were not collected by the garbage collector. 
I'm not sure what is the exact explanation here, but it solved my problem.

* Fix lint issue

* Fix lint issue

* Update src/components/connectAdvanced.js

Remove comment

Co-Authored-By: Tim Dorr <timdorr@users.noreply.github.com>
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