[16.8.6] Aggressive cleanup to assist garbage collection #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
At Discord, we were experiencing serious memory leaks when upgrading to React with Fiber internals. We spent a lot of time investigating but ultimately ended on this fork to unblock us. These changes are made on top of the tagged 16.8.6 release.
If you want to try this build, you can use use
"react-dom": "discordapp/react#cfda84f6b3c49a1398709cf43b3b959366f7e01a"
to yourpackage.json
.I still don't know whether the root cause of the memory leak is in userland or framework design. I do know the node-to-node pointers and fiber <-> host pointers make big memory leaks possible. See associated discussion in facebook#15157.
Changes
b0194a0
Clear the Fiber node's
nextEffect
pointers when finishing effect processing. This helps alleviate the long fiber chains that we saw in the profiler.d28ee48
This clears the stateNode (pointer to DOM node and class instances) described above when unmounting. It appears it's easy to keep references to detached DOM nodes from leaking fiber nodes.
2e5ee2f and c31cc03
At this point, we're desperate. On unmount, I clear the host node's pointer to the Fiber node. This is most definitely a hack but with this change, we are no longer seeing memory leaks.