Skip to content

Commit

Permalink
Resolve Paper leak on Android (facebook#46896)
Browse files Browse the repository at this point in the history
Summary:

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`

Differential Revision: D64054042
  • Loading branch information
rozele authored and facebook-github-bot committed Oct 8, 2024
1 parent cbc0978 commit 17a0b63
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1391,14 +1391,14 @@ private void detachRootViewFromInstance(ReactRoot reactRoot, ReactContext reactC
new RuntimeException(
"detachRootViewFromInstance called with ReactRootView with invalid id"));
}

clearReactRoot(reactRoot);
} else {
reactContext
.getCatalystInstance()
.getJSModule(AppRegistry.class)
.unmountApplicationComponentAtRootTag(reactRoot.getRootViewTag());
}

clearReactRoot(reactRoot);
}

@ThreadConfined(UI)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ public synchronized void removeRootView(int rootViewTag) {
View rootView = mTagsToViews.get(rootViewTag);
dropView(rootView);
mRootTags.delete(rootViewTag);
rootView.setId(View.NO_ID);
}

/**
Expand Down

0 comments on commit 17a0b63

Please sign in to comment.