From 5f94d0f1744d2a326c4d9fd74bfc15692f6ce56f Mon Sep 17 00:00:00 2001 From: paulshen Date: Thu, 11 Jul 2019 14:14:04 -0700 Subject: [PATCH] clean up nextEffect pointers --- .../react-reconciler/src/ReactFiberWorkLoop.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.js b/packages/react-reconciler/src/ReactFiberWorkLoop.js index b05e42a5512d..444e8a15250a 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.js @@ -1712,6 +1712,16 @@ function commitRootImpl(root) { rootDoesHavePassiveEffects = false; rootWithPendingPassiveEffects = root; pendingPassiveEffectsExpirationTime = expirationTime; + } else { + // We are done with the effect chain at this point so let's clear the + // nextEffect pointers to assist with GC. If we have passive effects, we'll + // clear this in flushPassiveEffects. + nextEffect = firstEffect; + while (nextEffect !== null) { + const nextNextEffect = nextEffect.nextEffect; + nextEffect.nextEffect = null; + nextEffect = nextNextEffect; + } } // Check if there's remaining work on this root @@ -1947,7 +1957,10 @@ export function flushPassiveEffects() { captureCommitPhaseError(effect, error); } } - effect = effect.nextEffect; + const nextNextEffect = effect.nextEffect; + // Remove nextEffect pointer to assist GC + effect.nextEffect = null; + effect = nextNextEffect; } if (enableSchedulerTracing) {