Skip to content

Commit b41937e

Browse files
javachefacebook-github-bot
authored andcommitted
Fix ReactInstanceManager leak (#41719)
Summary: Pull Request resolved: #41719 We leak ReactInstanceManager into a static singleton in `ReactCxxErrorHandler.setHandleErrorFunc`. Clean it up in `destroy()`. Changelog: [Internal] Reviewed By: cortinico Differential Revision: D51706624 fbshipit-source-id: 642825ba14ff0a9710b4435f5fb6026b3a81b711
1 parent 424ac63 commit b41937e

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ public void handleCxxError(Exception e) {
387387
mDevSupportManager.handleException(e);
388388
}
389389

390-
public void registerCxxErrorHandlerFunc() {
390+
private void registerCxxErrorHandlerFunc() {
391391
Class[] parameterTypes = new Class[1];
392392
parameterTypes[0] = Exception.class;
393393
Method handleCxxErrorFunc = null;
@@ -399,6 +399,10 @@ public void registerCxxErrorHandlerFunc() {
399399
ReactCxxErrorHandler.setHandleErrorFunc(this, handleCxxErrorFunc);
400400
}
401401

402+
private void unregisterCxxErrorHandlerFunc() {
403+
ReactCxxErrorHandler.setHandleErrorFunc(null, null);
404+
}
405+
402406
static void initializeSoLoaderIfNecessary(Context applicationContext) {
403407
// Call SoLoader.initialize here, this is required for apps that does not use exopackage and
404408
// does not use SoLoader for loading other native code except from the one used by React Native
@@ -747,23 +751,22 @@ public void destroy() {
747751
}
748752

749753
moveToBeforeCreateLifecycleState();
750-
751-
if (mCreateReactContextThread != null) {
752-
mCreateReactContextThread = null;
753-
}
754-
755754
mMemoryPressureRouter.destroy(mApplicationContext);
755+
unregisterCxxErrorHandlerFunc();
756756

757+
mCreateReactContextThread = null;
757758
synchronized (mReactContextLock) {
758759
if (mCurrentReactContext != null) {
759760
mCurrentReactContext.destroy();
760761
mCurrentReactContext = null;
761762
}
762763
}
764+
763765
mHasStartedCreatingInitialContext = false;
764766
mCurrentActivity = null;
765767

766768
ResourceDrawableIdHelper.getInstance().clear();
769+
767770
mHasStartedDestroying = false;
768771
synchronized (mHasStartedDestroying) {
769772
mHasStartedDestroying.notifyAll();

0 commit comments

Comments
 (0)