Skip to content

Commit

Permalink
Fix ReactInstanceManager leak (#41719)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
javache authored and facebook-github-bot committed Nov 30, 2023
1 parent 424ac63 commit b41937e
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public void handleCxxError(Exception e) {
mDevSupportManager.handleException(e);
}

public void registerCxxErrorHandlerFunc() {
private void registerCxxErrorHandlerFunc() {
Class[] parameterTypes = new Class[1];
parameterTypes[0] = Exception.class;
Method handleCxxErrorFunc = null;
Expand All @@ -399,6 +399,10 @@ public void registerCxxErrorHandlerFunc() {
ReactCxxErrorHandler.setHandleErrorFunc(this, handleCxxErrorFunc);
}

private void unregisterCxxErrorHandlerFunc() {
ReactCxxErrorHandler.setHandleErrorFunc(null, null);
}

static void initializeSoLoaderIfNecessary(Context applicationContext) {
// Call SoLoader.initialize here, this is required for apps that does not use exopackage and
// does not use SoLoader for loading other native code except from the one used by React Native
Expand Down Expand Up @@ -747,23 +751,22 @@ public void destroy() {
}

moveToBeforeCreateLifecycleState();

if (mCreateReactContextThread != null) {
mCreateReactContextThread = null;
}

mMemoryPressureRouter.destroy(mApplicationContext);
unregisterCxxErrorHandlerFunc();

mCreateReactContextThread = null;
synchronized (mReactContextLock) {
if (mCurrentReactContext != null) {
mCurrentReactContext.destroy();
mCurrentReactContext = null;
}
}

mHasStartedCreatingInitialContext = false;
mCurrentActivity = null;

ResourceDrawableIdHelper.getInstance().clear();

mHasStartedDestroying = false;
synchronized (mHasStartedDestroying) {
mHasStartedDestroying.notifyAll();
Expand Down

0 comments on commit b41937e

Please sign in to comment.