Skip to content

Commit 9b2fb24

Browse files
authored
Clear memoizedState on unmount of fiber to avoid memory leak (facebook#14218)
* Clear properties on unmount of fiber to ensure objects are not retained
1 parent a22fabc commit 9b2fb24

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

‎packages/react-reconciler/src/ReactFiberCommitWork.js‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,11 +726,20 @@ function detachFiber(current: Fiber) {
726726
// get GC:ed but we don't know which for sure which parent is the current
727727
// one so we'll settle for GC:ing the subtree of this child. This child
728728
// itself will be GC:ed when the parent updates the next time.
729+
// We do not null out the 'nextEffect' field as it causes tests to fail.
729730
current.return = null;
730731
current.child = null;
732+
current.memoizedState = null;
733+
current.updateQueue = null;
734+
current.firstEffect = null;
735+
current.lastEffect = null;
731736
if (current.alternate) {
732-
current.alternate.child = null;
733737
current.alternate.return = null;
738+
current.alternate.child = null;
739+
current.alternate.memoizedState = null;
740+
current.alternate.updateQueue = null;
741+
current.alternate.firstEffect = null;
742+
current.alternate.lastEffect = null;
734743
}
735744
}
736745

0 commit comments

Comments
 (0)