Skip to content

Commit dbf0984

Browse files
javachefacebook-github-bot
authored andcommitted
Schedule CatalystInstanceImpl destruction using new thread (#41720)
Summary: Pull Request resolved: #41720 We currently go via the UI thread, so we can use AsyncTask to schedule the final bit of async ReactContext destruction. This is a requirement for the AsyncTask API, which is also deprecated. We should figure out a better way to schedule and re-use threads across React Native Android, but until then, we can just create a new Thread here, which is also what we do for instance creation. Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D51706689 fbshipit-source-id: cf17e20e91b195b956b1701e6d91d563fdba4d15
1 parent 847f5de commit dbf0984

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

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

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
1212

1313
import android.content.res.AssetManager;
14-
import android.os.AsyncTask;
1514
import androidx.annotation.Nullable;
1615
import com.facebook.common.logging.FLog;
1716
import com.facebook.infer.annotation.Assertions;
@@ -374,30 +373,24 @@ public void destroy() {
374373
mTurboModuleRegistry.invalidate();
375374
}
376375

377-
getReactQueueConfiguration()
378-
.getUIQueueThread()
379-
.runOnQueue(
376+
// Kill non-UI threads from neutral third party
377+
// potentially expensive, so don't run on UI thread
378+
new Thread(
380379
() -> {
381-
// AsyncTask.execute must be executed from the UI Thread
382-
AsyncTask.execute(
383-
() -> {
384-
// Kill non-UI threads from neutral third party
385-
// potentially expensive, so don't run on UI thread
386-
387-
// contextHolder is used as a lock to guard against
388-
// other users of the JS VM having the VM destroyed
389-
// underneath them, so notify them before we reset
390-
// Native
391-
mJavaScriptContextHolder.clear();
392-
393-
mHybridData.resetNative();
394-
getReactQueueConfiguration().destroy();
395-
FLog.d(
396-
ReactConstants.TAG, "CatalystInstanceImpl.destroy() end");
397-
ReactMarker.logMarker(
398-
ReactMarkerConstants.DESTROY_CATALYST_INSTANCE_END);
399-
});
400-
});
380+
// contextHolder is used as a lock to guard against
381+
// other users of the JS VM having the VM destroyed
382+
// underneath them, so notify them before we reset
383+
// Native
384+
mJavaScriptContextHolder.clear();
385+
386+
mHybridData.resetNative();
387+
getReactQueueConfiguration().destroy();
388+
FLog.w(ReactConstants.TAG, "CatalystInstanceImpl.destroy() end");
389+
ReactMarker.logMarker(
390+
ReactMarkerConstants.DESTROY_CATALYST_INSTANCE_END);
391+
},
392+
"destroy_react_context")
393+
.start();
401394
});
402395
});
403396

0 commit comments

Comments
 (0)