Skip to content

Commit

Permalink
Fix fiber memory leak with runAllPassiveEffectDestroysBeforeCreates (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm committed Apr 9, 2020
1 parent ca1a703 commit 0566b70
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
25 changes: 14 additions & 11 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -2368,12 +2368,15 @@ function flushPassiveEffectsImpl() {
}
}
}
} else {
// Note: This currently assumes there are no passive effects on the root fiber
// because the root is not part of its own effect list.
// This could change in the future.
let effect = root.current.firstEffect;
while (effect !== null) {
}
// Note: This currently assumes there are no passive effects on the root fiber
// because the root is not part of its own effect list.
// This could change in the future.
let effect = root.current.firstEffect;
while (effect !== null) {
// We do this work above if this flag is enabled, so we shouldn't be
// doing it here.
if (!runAllPassiveEffectDestroysBeforeCreates) {
if (__DEV__) {
setCurrentDebugFiberInDEV(effect);
invokeGuardedCallback(null, commitPassiveHookEffects, null, effect);
Expand All @@ -2391,12 +2394,12 @@ function flushPassiveEffectsImpl() {
captureCommitPhaseError(effect, error);
}
}

const nextNextEffect = effect.nextEffect;
// Remove nextEffect pointer to assist GC
effect.nextEffect = null;
effect = nextNextEffect;
}

const nextNextEffect = effect.nextEffect;
// Remove nextEffect pointer to assist GC
effect.nextEffect = null;
effect = nextNextEffect;
}

if (enableProfilerTimer && enableProfilerCommitHooks) {
Expand Down
25 changes: 14 additions & 11 deletions packages/react-reconciler/src/ReactFiberWorkLoop.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -2368,12 +2368,15 @@ function flushPassiveEffectsImpl() {
}
}
}
} else {
// Note: This currently assumes there are no passive effects on the root fiber
// because the root is not part of its own effect list.
// This could change in the future.
let effect = root.current.firstEffect;
while (effect !== null) {
}
// Note: This currently assumes there are no passive effects on the root fiber
// because the root is not part of its own effect list.
// This could change in the future.
let effect = root.current.firstEffect;
while (effect !== null) {
// We do this work above if this flag is enabled, so we shouldn't be
// doing it here.
if (!runAllPassiveEffectDestroysBeforeCreates) {
if (__DEV__) {
setCurrentDebugFiberInDEV(effect);
invokeGuardedCallback(null, commitPassiveHookEffects, null, effect);
Expand All @@ -2391,12 +2394,12 @@ function flushPassiveEffectsImpl() {
captureCommitPhaseError(effect, error);
}
}

const nextNextEffect = effect.nextEffect;
// Remove nextEffect pointer to assist GC
effect.nextEffect = null;
effect = nextNextEffect;
}

const nextNextEffect = effect.nextEffect;
// Remove nextEffect pointer to assist GC
effect.nextEffect = null;
effect = nextNextEffect;
}

if (enableProfilerTimer && enableProfilerCommitHooks) {
Expand Down

0 comments on commit 0566b70

Please sign in to comment.