mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Clean listeners during destroy of ReactContext
Summary: This diff cleans listeners on the destruction of the ReactContext. changelog: [inernal] internal Reviewed By: JoshuaGross Differential Revision: D26259929 fbshipit-source-id: 1843cabdac2fa3e67dcc890afd923b82472d8f66
This commit is contained in:
committed by
Facebook GitHub Bot
parent
98165a23f6
commit
d79212120b
@@ -8,6 +8,7 @@
|
||||
package com.facebook.react.bridge;
|
||||
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.config.ReactFeatureFlags;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -44,6 +45,8 @@ public class JSIModuleRegistry {
|
||||
JSIModuleHolder moduleHolder = entry.getValue();
|
||||
moduleHolder.notifyJSInstanceDestroy();
|
||||
}
|
||||
mModules.clear();
|
||||
if (ReactFeatureFlags.enableReactContextCleanupFix) {
|
||||
mModules.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
package com.facebook.react.bridge;
|
||||
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.config.ReactFeatureFlags;
|
||||
import com.facebook.react.module.annotations.ReactModule;
|
||||
import com.facebook.systrace.Systrace;
|
||||
import java.util.ArrayList;
|
||||
@@ -84,7 +85,9 @@ public class NativeModuleRegistry {
|
||||
for (ModuleHolder module : mModules.values()) {
|
||||
module.destroy();
|
||||
}
|
||||
mModules.clear();
|
||||
if (ReactFeatureFlags.enableReactContextCleanupFix) {
|
||||
mModules.clear();
|
||||
}
|
||||
} finally {
|
||||
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.facebook.react.bridge.queue.MessageQueueThread;
|
||||
import com.facebook.react.bridge.queue.ReactQueueConfiguration;
|
||||
import com.facebook.react.common.LifecycleState;
|
||||
import com.facebook.react.common.ReactConstants;
|
||||
import com.facebook.react.config.ReactFeatureFlags;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
@@ -296,6 +297,11 @@ public class ReactContext extends ContextWrapper {
|
||||
if (mCatalystInstance != null) {
|
||||
mCatalystInstance.destroy();
|
||||
}
|
||||
if (ReactFeatureFlags.enableReactContextCleanupFix) {
|
||||
mLifecycleEventListeners.clear();
|
||||
mActivityEventListeners.clear();
|
||||
mWindowFocusEventListeners.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/** Should be called by the hosting Fragment in {@link Fragment#onActivityResult} */
|
||||
|
||||
@@ -62,4 +62,7 @@ public class ReactFeatureFlags {
|
||||
|
||||
/** Enables Static ViewConfig in RN Android native code. */
|
||||
public static boolean enableExperimentalStaticViewConfigs = false;
|
||||
|
||||
/** Enables a more aggressive cleanup during destruction of ReactContext */
|
||||
public static boolean enableReactContextCleanupFix = false;
|
||||
}
|
||||
|
||||
@@ -247,8 +247,11 @@ public class UIManagerModule extends ReactContextBaseJavaModule
|
||||
mEventDispatcher.onCatalystInstanceDestroyed();
|
||||
mUIImplementation.onCatalystInstanceDestroyed();
|
||||
|
||||
getReactApplicationContext().removeLifecycleEventListener(this);
|
||||
getReactApplicationContext().unregisterComponentCallbacks(mMemoryTrimCallback);
|
||||
ReactApplicationContext reactApplicationContext = getReactApplicationContext();
|
||||
if (ReactFeatureFlags.enableReactContextCleanupFix) {
|
||||
reactApplicationContext.removeLifecycleEventListener(this);
|
||||
}
|
||||
reactApplicationContext.unregisterComponentCallbacks(mMemoryTrimCallback);
|
||||
YogaNodePool.get().clear();
|
||||
ViewManagerPropertyUpdater.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user