Skip to content

Commit d9c532d

Browse files
committed
[Draft] Add feature flag: enableStrongMemoryCleanup
1 parent 00d4f95 commit d9c532d

12 files changed

+53
-2
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
enableSuspenseCallback,
3636
enableScopeAPI,
3737
enableStrictEffects,
38+
enableStrongMemoryCleanup,
3839
} from 'shared/ReactFeatureFlags';
3940
import {
4041
FunctionComponent,
@@ -1212,9 +1213,28 @@ function detachFiberMutation(fiber: Fiber) {
12121213
fiber.return = null;
12131214
}
12141215

1215-
export function detachFiberAfterEffects(fiber: Fiber): void {
1216+
export function detachFiberAfterEffects(
1217+
fiber: Fiber,
1218+
recurseIntoSibbling: ?boolean,
1219+
): void {
12161220
// Null out fields to improve GC for references that may be lingering (e.g. DevTools).
12171221
// Note that we already cleared the return pointer in detachFiberMutation().
1222+
if (enableStrongMemoryCleanup) {
1223+
if (fiber.child) {
1224+
detachFiberAfterEffects(fiber.child, true);
1225+
}
1226+
if (fiber.sibling && recurseIntoSibbling === true) {
1227+
detachFiberAfterEffects(fiber.sibling, true);
1228+
}
1229+
if (fiber.stateNode) {
1230+
Object.keys(fiber.stateNode).forEach(key => {
1231+
if (key.indexOf('__react') === 0) {
1232+
delete fiber.stateNode[key];
1233+
}
1234+
});
1235+
}
1236+
fiber.return = null;
1237+
}
12181238
fiber.alternate = null;
12191239
fiber.child = null;
12201240
fiber.deletions = null;

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
enableSuspenseCallback,
3636
enableScopeAPI,
3737
enableStrictEffects,
38+
enableStrongMemoryCleanup,
3839
} from 'shared/ReactFeatureFlags';
3940
import {
4041
FunctionComponent,
@@ -1212,9 +1213,28 @@ function detachFiberMutation(fiber: Fiber) {
12121213
fiber.return = null;
12131214
}
12141215

1215-
export function detachFiberAfterEffects(fiber: Fiber): void {
1216+
export function detachFiberAfterEffects(
1217+
fiber: Fiber,
1218+
recurseIntoSibbling: ?boolean,
1219+
): void {
12161220
// Null out fields to improve GC for references that may be lingering (e.g. DevTools).
12171221
// Note that we already cleared the return pointer in detachFiberMutation().
1222+
if (enableStrongMemoryCleanup) {
1223+
if (fiber.child) {
1224+
detachFiberAfterEffects(fiber.child, true);
1225+
}
1226+
if (fiber.sibling && recurseIntoSibbling === true) {
1227+
detachFiberAfterEffects(fiber.sibling, true);
1228+
}
1229+
if (fiber.stateNode) {
1230+
Object.keys(fiber.stateNode).forEach(key => {
1231+
if (key.indexOf('__react') === 0) {
1232+
delete fiber.stateNode[key];
1233+
}
1234+
});
1235+
}
1236+
fiber.return = null;
1237+
}
12181238
fiber.alternate = null;
12191239
fiber.child = null;
12201240
fiber.deletions = null;

packages/shared/ReactFeatureFlags.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ export const disableNativeComponentFrames = false;
112112
// If there are no still-mounted boundaries, the errors should be rethrown.
113113
export const skipUnmountedBoundaries = false;
114114

115+
export const enableStrongMemoryCleanup = true;
116+
115117
// --------------------------
116118
// Future APIs to be deprecated
117119
// --------------------------

packages/shared/forks/ReactFeatureFlags.native-fb.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const enableLegacyFBSupport = false;
4646
export const enableFilterEmptyStringAttributesDOM = false;
4747
export const disableNativeComponentFrames = false;
4848
export const skipUnmountedBoundaries = false;
49+
export const enableStrongMemoryCleanup = true;
4950

5051
export const enableNewReconciler = false;
5152
export const deferRenderPhaseUpdateToNextBatch = true;

packages/shared/forks/ReactFeatureFlags.native-oss.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const enableLegacyFBSupport = false;
4545
export const enableFilterEmptyStringAttributesDOM = false;
4646
export const disableNativeComponentFrames = false;
4747
export const skipUnmountedBoundaries = false;
48+
export const enableStrongMemoryCleanup = true;
4849

4950
export const enableNewReconciler = false;
5051
export const deferRenderPhaseUpdateToNextBatch = true;

packages/shared/forks/ReactFeatureFlags.test-renderer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const enableLegacyFBSupport = false;
4545
export const enableFilterEmptyStringAttributesDOM = false;
4646
export const disableNativeComponentFrames = false;
4747
export const skipUnmountedBoundaries = false;
48+
export const enableStrongMemoryCleanup = true;
4849

4950
export const enableNewReconciler = false;
5051
export const deferRenderPhaseUpdateToNextBatch = true;

packages/shared/forks/ReactFeatureFlags.test-renderer.native.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const enableLegacyFBSupport = false;
4545
export const enableFilterEmptyStringAttributesDOM = false;
4646
export const disableNativeComponentFrames = false;
4747
export const skipUnmountedBoundaries = false;
48+
export const enableStrongMemoryCleanup = true;
4849

4950
export const enableNewReconciler = false;
5051
export const deferRenderPhaseUpdateToNextBatch = true;

packages/shared/forks/ReactFeatureFlags.test-renderer.www.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const enableLegacyFBSupport = false;
4545
export const enableFilterEmptyStringAttributesDOM = false;
4646
export const disableNativeComponentFrames = false;
4747
export const skipUnmountedBoundaries = false;
48+
export const enableStrongMemoryCleanup = true;
4849

4950
export const enableNewReconciler = false;
5051
export const deferRenderPhaseUpdateToNextBatch = true;

packages/shared/forks/ReactFeatureFlags.testing.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const enableLegacyFBSupport = false;
4545
export const enableFilterEmptyStringAttributesDOM = false;
4646
export const disableNativeComponentFrames = false;
4747
export const skipUnmountedBoundaries = false;
48+
export const enableStrongMemoryCleanup = true;
4849

4950
export const enableNewReconciler = false;
5051
export const deferRenderPhaseUpdateToNextBatch = true;

packages/shared/forks/ReactFeatureFlags.testing.www.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const enableLegacyFBSupport = !__EXPERIMENTAL__;
4545
export const enableFilterEmptyStringAttributesDOM = false;
4646
export const disableNativeComponentFrames = false;
4747
export const skipUnmountedBoundaries = true;
48+
export const enableStrongMemoryCleanup = true;
4849

4950
export const enableNewReconciler = false;
5051
export const deferRenderPhaseUpdateToNextBatch = true;

packages/shared/forks/ReactFeatureFlags.www-dynamic.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export const disableNativeComponentFrames = false;
5252
export const createRootStrictEffectsByDefault = false;
5353
export const enableStrictEffects = false;
5454
export const enableUseRefAccessWarning = __VARIANT__;
55+
export const enableStrongMemoryCleanup = __VARIANT__;
5556

5657
export const enableProfilerNestedUpdateScheduledHook = __VARIANT__;
5758
export const disableSchedulerTimeoutInWorkLoop = __VARIANT__;

packages/shared/forks/ReactFeatureFlags.www.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const {
3333
disableSchedulerTimeoutInWorkLoop,
3434
enableSyncMicroTasks,
3535
enableLazyContextPropagation,
36+
enableStrongMemoryCleanup,
3637
} = dynamicFeatureFlags;
3738

3839
// On WWW, __EXPERIMENTAL__ is used for a new modern build.

0 commit comments

Comments
 (0)