Resolve Paper leak on Android (#46896)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/46896

On Android Paper UIManager, when calling `ReactRootView.unmountReactApplication`, the ReactRootView tag is unset [here](https://github.com/facebook/react-native/blob/main/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java#L926), before the round trip unmount operation to JS makes it's way back to a `dropView` call on `NativeViewHierarchyManager`.

In practice, this means that legacy architecture apps that unmount surfaces via `ReactRootView.unmountReactApplication` leak references to Views, and the "finalization" step (`onDropViewInstance`) is not universally called.

This is an attempt to fix the issue by skipping the `clearReactRoot` step on Paper, instead waiting for the round trip `UIManager.removeRootView` call.

## Changelog

[Android][Fixed] Fix issue where `onDropViewInstance` cleanup was not being handled after `ReactRootView.unmountReactApplication`

Reviewed By: javache

Differential Revision: D64054042

fbshipit-source-id: b8b8c237796674ca23a332e57a1bf2e07ab5af13
This commit is contained in:
Eric Rozell
2024-10-09 05:25:10 -07:00
committed by Facebook GitHub Bot
parent 87bae7f734
commit 0449630612
2 changed files with 5 additions and 2 deletions
@@ -1391,14 +1391,14 @@ public class ReactInstanceManager {
new RuntimeException(
"detachRootViewFromInstance called with ReactRootView with invalid id"));
}
clearReactRoot(reactRoot);
} else {
reactContext
.getCatalystInstance()
.getJSModule(AppRegistry.class)
.unmountApplicationComponentAtRootTag(reactRoot.getRootViewTag());
}
clearReactRoot(reactRoot);
}
@ThreadConfined(UI)
@@ -674,6 +674,9 @@ public class NativeViewHierarchyManager {
View rootView = mTagsToViews.get(rootViewTag);
dropView(rootView);
mRootTags.delete(rootViewTag);
if (rootView != null) {
rootView.setId(View.NO_ID);
}
}
/**