Skip to content

Commit b4178af

Browse files
paulshensebmarkbage
authored andcommitted
clean up nextEffect pointers (#16115)
1 parent 997154b commit b4178af

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

packages/react-reconciler/src/ReactFiberWorkLoop.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,6 +1712,16 @@ function commitRootImpl(root) {
17121712
rootDoesHavePassiveEffects = false;
17131713
rootWithPendingPassiveEffects = root;
17141714
pendingPassiveEffectsExpirationTime = expirationTime;
1715+
} else {
1716+
// We are done with the effect chain at this point so let's clear the
1717+
// nextEffect pointers to assist with GC. If we have passive effects, we'll
1718+
// clear this in flushPassiveEffects.
1719+
nextEffect = firstEffect;
1720+
while (nextEffect !== null) {
1721+
const nextNextEffect = nextEffect.nextEffect;
1722+
nextEffect.nextEffect = null;
1723+
nextEffect = nextNextEffect;
1724+
}
17151725
}
17161726

17171727
// Check if there's remaining work on this root
@@ -1947,7 +1957,10 @@ export function flushPassiveEffects() {
19471957
captureCommitPhaseError(effect, error);
19481958
}
19491959
}
1950-
effect = effect.nextEffect;
1960+
const nextNextEffect = effect.nextEffect;
1961+
// Remove nextEffect pointer to assist GC
1962+
effect.nextEffect = null;
1963+
effect = nextNextEffect;
19511964
}
19521965

19531966
if (enableSchedulerTracing) {

0 commit comments

Comments
 (0)