Fix leak checker crash in bridgeless mode

Summary:
Fast follow to D26727461 (https://github.com/facebook/react-native/commit/34d189ae09b32261e1a2055263bd425f8a82a4c6), in bridgeless mode, `_contextContainer` doesn't have bridge, so avoid setting up `garbageCollectionTrigger`.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D27173725

fbshipit-source-id: 5530c43638c17fb03e065c11667786efe9f3ef11
This commit is contained in:
Peter Argany authored and Facebook GitHub Bot committed 2021-03-18 18:29:38 -07:00
1 parent cfb5b5e20a
commit ac7ba3ea16
1 file changed
+10 -7
+10 -7
View File
@@ -291,13 +291,16 @@ static BackgroundExecutor RCTGetBackgroundExecutor()
}
#ifdef REACT_NATIVE_DEBUG
RCTBridge *bridge = (RCTBridge *)unwrapManagedObjectWeakly(_contextContainer->at<std::shared_ptr<void>>("Bridge"));
toolbox.garbageCollectionTrigger = [bridge]() {
RCTCxxBridge *batchedBridge = (RCTCxxBridge *)([bridge batchedBridge] ?: bridge);
if ([batchedBridge respondsToSelector:@selector(forceGarbageCollection)]) {
[batchedBridge forceGarbageCollection];
}
};
auto optionalBridge = _contextContainer->find<std::shared_ptr<void>>("Bridge");
if (optionalBridge) {
RCTBridge *bridge = unwrapManagedObjectWeakly(optionalBridge.value());
toolbox.garbageCollectionTrigger = [bridge]() {
RCTCxxBridge *batchedBridge = (RCTCxxBridge *)([bridge batchedBridge] ?: bridge);
if ([batchedBridge respondsToSelector:@selector(forceGarbageCollection)]) {
[batchedBridge forceGarbageCollection];
}
};
}
#endif
toolbox.synchronousEventBeatFactory = [runtimeExecutor](EventBeat::SharedOwnerBox const &ownerBox) {