Implement release of FabricUIManager resources
Reviewed By: achen1 Differential Revision: D8232155 fbshipit-source-id: 6683c692a830f5a73aab2c606167e54d668ae5c2
This commit is contained in:
parent
6aea98441a
commit
8529b1ee91
|
@ -30,6 +30,11 @@ public class ReactBridgeIdleSignaler implements NotThreadSafeBridgeIdleDebugList
|
|||
mBridgeIdleSemaphore.release();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBridgeDestroyed() {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransitionToBridgeBusy() {
|
||||
mIsBridgeIdle = false;
|
||||
|
|
|
@ -338,10 +338,14 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
|||
@Override
|
||||
public void run() {
|
||||
mNativeModuleRegistry.notifyJSInstanceDestroy();
|
||||
mJSIModuleRegistry.notifyJSInstanceDestroy();
|
||||
boolean wasIdle = (mPendingJSCalls.getAndSet(0) == 0);
|
||||
if (!wasIdle && !mBridgeIdleListeners.isEmpty()) {
|
||||
if (!mBridgeIdleListeners.isEmpty()) {
|
||||
for (NotThreadSafeBridgeIdleDebugListener listener : mBridgeIdleListeners) {
|
||||
listener.onTransitionToBridgeIdle();
|
||||
if (!wasIdle) {
|
||||
listener.onTransitionToBridgeIdle();
|
||||
}
|
||||
listener.onBridgeDestroyed();
|
||||
}
|
||||
}
|
||||
AsyncTask.execute(
|
||||
|
@ -351,7 +355,8 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
|||
// Kill non-UI threads from neutral third party
|
||||
// potentially expensive, so don't run on UI thread
|
||||
|
||||
// contextHolder is used as a lock to guard against other users of the JS VM having
|
||||
// contextHolder is used as a lock to guard against other users of the JS VM
|
||||
// having
|
||||
// the VM destroyed underneath them, so notify them before we resetNative
|
||||
mJavaScriptContextHolder.clear();
|
||||
|
||||
|
|
|
@ -4,4 +4,16 @@ package com.facebook.react.bridge;
|
|||
* Marker interface used to represent a JSI Module.
|
||||
*/
|
||||
public interface JSIModule {
|
||||
|
||||
/**
|
||||
* This is called at the end of {@link CatalystApplicationFragment#createCatalystInstance()}
|
||||
* after the CatalystInstance has been created, in order to initialize NativeModules that require
|
||||
* the CatalystInstance or JS modules.
|
||||
*/
|
||||
void initialize();
|
||||
|
||||
/**
|
||||
* Called before {CatalystInstance#onHostDestroy}
|
||||
*/
|
||||
void onCatalystInstanceDestroy();
|
||||
}
|
||||
|
|
|
@ -16,8 +16,15 @@ public class JSIModuleHolder {
|
|||
return mModule;
|
||||
}
|
||||
mModule = mSpec.getJSIModuleProvider().get();
|
||||
mModule.initialize();
|
||||
}
|
||||
}
|
||||
return mModule;
|
||||
}
|
||||
|
||||
public void notifyJSInstanceDestroy() {
|
||||
if (mModule != null) {
|
||||
mModule.onCatalystInstanceDestroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,4 +25,9 @@ public class JSIModuleRegistry {
|
|||
}
|
||||
}
|
||||
|
||||
public void notifyJSInstanceDestroy() {
|
||||
for (JSIModuleHolder moduleHolder : mModules.values()) {
|
||||
moduleHolder.notifyJSInstanceDestroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,4 +28,9 @@ public interface NotThreadSafeBridgeIdleDebugListener {
|
|||
* Called when the bridge was in an idle state and executes a JS call or callback.
|
||||
*/
|
||||
void onTransitionToBridgeBusy();
|
||||
|
||||
/**
|
||||
* Called when the bridge is destroyed
|
||||
*/
|
||||
void onBridgeDestroyed();
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ import com.facebook.react.fabric.events.FabricEventEmitter;
|
|||
import com.facebook.react.modules.i18nmanager.I18nUtil;
|
||||
import com.facebook.react.uimanager.DisplayMetricsHolder;
|
||||
import com.facebook.react.uimanager.NativeViewHierarchyManager;
|
||||
import com.facebook.react.uimanager.OnLayoutEvent;
|
||||
import com.facebook.react.uimanager.ReactRootViewTagGenerator;
|
||||
import com.facebook.react.uimanager.ReactShadowNode;
|
||||
import com.facebook.react.uimanager.ReactShadowNodeImpl;
|
||||
|
@ -84,10 +83,6 @@ public class FabricUIManager implements UIManager, JSHandler {
|
|||
mFabricReconciler = new FabricReconciler(mUIViewOperationQueue);
|
||||
mEventDispatcher = eventDispatcher;
|
||||
mJSContext = jsContext;
|
||||
|
||||
FabricEventEmitter eventEmitter =
|
||||
new FabricEventEmitter(reactContext, this);
|
||||
eventDispatcher.registerEventEmitter(FABRIC, eventEmitter);
|
||||
}
|
||||
|
||||
public void setBinding(FabricBinding binding) {
|
||||
|
@ -538,4 +533,16 @@ public class FabricUIManager implements UIManager, JSHandler {
|
|||
mBinding.dispatchEventToTarget(mJSContext.get(), mEventHandlerPointer, eventTarget, name, (WritableNativeMap) params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
FabricEventEmitter eventEmitter =
|
||||
new FabricEventEmitter(mReactApplicationContext, this);
|
||||
mEventDispatcher.registerEventEmitter(FABRIC, eventEmitter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCatalystInstanceDestroy() {
|
||||
mBinding.releaseEventHandler(mJSContext.get(), mEventHandlerPointer);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -42,6 +42,11 @@ public class DidJSUpdateUiDuringFrameDetector implements NotThreadSafeBridgeIdle
|
|||
mTransitionToBusyEvents.add(System.nanoTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void onBridgeDestroyed() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void onViewHierarchyUpdateEnqueued() {
|
||||
mViewHierarchyUpdateEnqueuedEvents.add(System.nanoTime());
|
||||
|
|
Loading…
Reference in New Issue