Skip to content

Commit 986cf18

Browse files
motiz88facebook-github-bot
authored andcommitted
Migrate ReactHost / ReactInstanceManager destroy() call sites to use invalidate() (#45082)
Summary: Pull Request resolved: #45082 Changelog: [Android][Breaking] `ReactNativeHost` invalidates the instance manager on `clear()` Changes `ReactNativeHost.clear()` to invalidate the underlying `ReactInstanceManager`, rather than merely destroying the instance. This is technically a **breaking change** because the underlying `ReactInstanceManager` may have escaped (via `ReactNativeHost.getReactInstanceManager()`) before the `clear()` call. In my reading of the API and of usages like [this one in Expo](https://github.com/expo/expo/blob/23a905b17065703882ebeda1fc9f65a05cc69fa7/packages/expo-dev-menu-interface/android/src/main/java/expo/interfaces/devmenu/ReactHostWrapper.kt#L117), this should rarely occur in practice. The plan: 1. D58811090: Add the basic `invalidate()` functionality. 2. **[This diff]**: Add `invalidate()` call sites where it makes sense in core. 3. [Upcoming diff]: Keep the Fusebox debugging target registered until the Host is explicitly invalidated. Reviewed By: javache Differential Revision: D58811091 fbshipit-source-id: 5dfebad46a2bdf3601642b3c3fe3e79e8695e193
1 parent a3db352 commit 986cf18

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactNativeHost.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ protected ReactNativeHost(Application application) {
4343
mApplication = application;
4444
}
4545

46-
/** Get the current {@link ReactInstanceManager} instance, or create one. */
46+
/**
47+
* Get the current {@link ReactInstanceManager} instance, or create one.
48+
*
49+
* <p>NOTE: Care must be taken when storing this reference outside of the ReactNativeHost
50+
* lifecycle. The ReactInstanceManager will be invalidated during {@link #clear()}, and may not be
51+
* used again afterwards.
52+
*/
4753
public ReactInstanceManager getReactInstanceManager() {
4854
if (mReactInstanceManager == null) {
4955
ReactMarker.logMarker(ReactMarkerConstants.INIT_REACT_RUNTIME_START);
@@ -64,11 +70,12 @@ public boolean hasInstance() {
6470
}
6571

6672
/**
67-
* Destroy the current instance and release the internal reference to it, allowing it to be GCed.
73+
* Destroy the current instance and invalidate the internal ReactInstanceManager, reclaiming its
74+
* resources and preventing it from being reused.
6875
*/
6976
public void clear() {
7077
if (mReactInstanceManager != null) {
71-
mReactInstanceManager.destroy();
78+
mReactInstanceManager.invalidate();
7279
mReactInstanceManager = null;
7380
}
7481
}

0 commit comments

Comments
 (0)