Add enable_nullify_catalyst_instance_on_destroy MC and gate setting mCatalystInstance to null in ReactContext

Summary:
Mostly for easing open-source migration and not making a backwards-incompatible change (yet), we'll set this to false by default. Every app can opt-in to this if wanted but it's not necessary. This change is part of experiments surrounding more-aggressive teardown for Fabric and Bridgeless mode.

Changelog: [Internal] - This has the effect of (by default) disabling the previous diff which caused ReactContext teardown to always set mCatalystInstance to null. Now that is opt-in behavior and off by default, so it's not longer a breaking change.

Reviewed By: mdvacca

Differential Revision: D18207302

fbshipit-source-id: 7acfc894415e966f652c7049849eef79c440a135
This commit is contained in:
Joshua Gross 2019-10-29 16:18:59 -07:00 коммит произвёл Facebook Github Bot
Родитель 55e974d9fa
Коммит 426868b6c2
2 изменённых файлов: 13 добавлений и 1 удалений

Просмотреть файл

@ -21,6 +21,7 @@ import com.facebook.infer.annotation.ThreadConfined;
import com.facebook.react.bridge.queue.MessageQueueThread; import com.facebook.react.bridge.queue.MessageQueueThread;
import com.facebook.react.bridge.queue.ReactQueueConfiguration; import com.facebook.react.bridge.queue.ReactQueueConfiguration;
import com.facebook.react.common.LifecycleState; import com.facebook.react.common.LifecycleState;
import com.facebook.react.config.ReactFeatureFlags;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.CopyOnWriteArraySet;
@ -272,7 +273,9 @@ public class ReactContext extends ContextWrapper {
if (mCatalystInstance != null) { if (mCatalystInstance != null) {
mCatalystInstance.destroy(); mCatalystInstance.destroy();
mCatalystInstance = null; if (ReactFeatureFlags.nullifyCatalystInstanceOnDestroy) {
mCatalystInstance = null;
}
} }
} }

Просмотреть файл

@ -61,4 +61,13 @@ public class ReactFeatureFlags {
* CatalystInstanceImpl `destroy` method. * CatalystInstanceImpl `destroy` method.
*/ */
public static boolean useCatalystTeardownV2 = false; public static boolean useCatalystTeardownV2 = false;
/**
* When the ReactContext is destroyed, should the CatalystInstance immediately be nullified? This
* is the safest thing to do since the CatalystInstance shouldn't be used, and should be
* garbage-collected after it's destroyed, but this is a breaking change in that many native
* modules assume that a ReactContext will always have a CatalystInstance. This will be deleted
* and the CatalystInstance will always be destroyed in some future release.
*/
public static boolean nullifyCatalystInstanceOnDestroy = false;
} }