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 in ReactComponentTreeDevtool #6753

Merged
merged 1 commit into from
May 12, 2016
Merged

Fix a memory leak in ReactComponentTreeDevtool #6753

merged 1 commit into from
May 12, 2016

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented May 12, 2016

ReactDebugTool used to only call purgeUnmountedComponents() while profiling, so information about unmounted instances kept accumulating when not profiling.

Additionally, unmounting in React Native and rendering to string did not correctly clean up the devtool.

Finally, the tests tested the wrong behavior and relied on explicit purgeUnmountedComponent() calls.

To fix this, we:

  • Test specifically that unmounting is enough to clean up the tree devtool.
  • Add missing onBeginFlush and onEndFlush calls to server and native rendering so ReactDebugTool knows when to copy the tree.

Fixes #6750.

Reviewers: @sebmarkbage @spicyj.

@@ -106,6 +106,11 @@ var ReactComponentTreeDevtool = {
},

purgeUnmountedComponents() {
if (ReactComponentTreeDevtool._preventPurging) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not a big fan of these but I’m not sure how else we can test the expected tree during server rendering, if ReactDebugTool cleans it up right before the batch. Alternatively we can make those integration tests instead in ReactPerf-test, but I like how comprehensive the suite for ReactComponentDebugTool is, so I don’t want to replicate the same complexity in ReactPerf-test.

Copy link
Collaborator

@sophiebits sophiebits May 12, 2016

Choose a reason for hiding this comment

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

Could you add another devtool in the test that checks the state at an appropriate time? If not or if that's too clunky, I think this seems fine too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I’d keep it this way for now. I’m not sure about this reliance on flush events anyway (#6046 (comment)), so I’d rather avoid relying on the order in which devtools are called for now.

@sophiebits
Copy link
Collaborator

Thanks.

`ReactDebugTool` used to only call `purgeUnmountedComponents()` while profiling, so information about unmounted instances kept accumulating when not profiling.

Additionally, unmounting in React Native and rendering to string did not correctly clean up the devtool.

Finally, the tests tested the wrong behavior and relied on explicit `purgeUnmountedComponent()` calls.

To fix this, we:

* Test specifically that unmounting is enough to clean up the tree devtool.
* Add missing `onBeginFlush` and `onEndFlush` calls to server and native rendering so `ReactDebugTool` knows when to copy the tree.

Fixes #6750
@ghost
Copy link

ghost commented May 12, 2016

@gaearon updated the pull request.

@gaearon gaearon merged commit de1bb7a into master May 12, 2016
@gaearon gaearon deleted the fix-6750 branch May 12, 2016 02:55
@zpao zpao modified the milestones: 15.y.0, 15.1.0 May 16, 2016
zpao pushed a commit that referenced this pull request May 20, 2016
Fix a memory leak in ReactComponentTreeDevtool
(cherry picked from commit de1bb7a)
@zpao zpao modified the milestones: 15.1.0, 15.y.0 May 20, 2016
This pull request was closed.
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.

New ReactPerf doesn’t free memory in DEV when not profiling
3 participants