Skip to content

Commit 5baf687

Browse files
Moses DeJongfacebook-github-bot
authored andcommitted
TurboModules: use weakSelf for block sent to main thread
Summary: TurboModules: use weakSelf for block sent to main thread. Changelog: [iOS][Fixed] - Use weakSelf in objc block instead of self. Reviewed By: RSNara Differential Revision: D33488938 fbshipit-source-id: d03c98fb59fbd1fc4b67686251ebec541e5d3e6c
1 parent 0ee6688 commit 5baf687

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

ReactCommon/react/nativemodule/core/platform/ios/RCTTurboModuleManager.mm

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,15 @@ - (TurboModuleHolder *)_getOrCreateTurboModuleHolder:(const char *)moduleName
437437
__block id<RCTTurboModule> module = nil;
438438

439439
if ([moduleClass conformsToProtocol:@protocol(RCTTurboModule)]) {
440+
__weak __typeof(self) weakSelf = self;
440441
dispatch_block_t work = ^{
441-
module = [self _createAndSetUpRCTTurboModule:moduleClass
442-
moduleName:moduleName
443-
moduleId:moduleHolder->getModuleId()];
442+
auto strongSelf = weakSelf;
443+
if (!strongSelf) {
444+
return;
445+
}
446+
module = [strongSelf _createAndSetUpRCTTurboModule:moduleClass
447+
moduleName:moduleName
448+
moduleId:moduleHolder->getModuleId()];
444449
};
445450

446451
if ([self _requiresMainQueueSetup:moduleClass]) {

0 commit comments

Comments
 (0)