Clear memoizedState on unmount of fiber to avoid memory leak (#14218)
* Clear properties on unmount of fiber to ensure objects are not retained
Dominic Gannaway committed
Nov 19, 2018 at 10:58 UTC
9b2fb24f99ebed9af2c092de7a5f31c38f8af97a
1 file changed
+10
-1
packages/react-reconciler/src/ReactFiberCommitWork.js
+10
-1
@@ -726,11 +726,20 @@ function detachFiber(current: Fiber) {
726
// get GC:ed but we don't know which for sure which parent is the current
727
// one so we'll settle for GC:ing the subtree of this child. This child
728
// 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.
730
current.return = null;
731
current.child = null;
732
+ current.memoizedState = null;
733
+ current.updateQueue = null;
734
+ current.firstEffect = null;
735
+ current.lastEffect = null;
736
if (current.alternate) {
732
- current.alternate.child = null;
737
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;
743
}
744
}
745