diff --git a/React/CoreModules/RCTLogBox.mm b/React/CoreModules/RCTLogBox.mm index 5e01f9ad017..0a3dc677bea 100644 --- a/React/CoreModules/RCTLogBox.mm +++ b/React/CoreModules/RCTLogBox.mm @@ -91,11 +91,16 @@ RCT_EXPORT_MODULE() RCT_EXPORT_METHOD(show) { if (RCTRedBoxGetEnabled()) { + __weak RCTLogBox *weakSelf = self; dispatch_async(dispatch_get_main_queue(), ^{ - if (!self->_view) { - self->_view = [[RCTLogBoxView alloc] initWithFrame:[UIScreen mainScreen].bounds bridge:self->_bridge]; + __strong RCTLogBox *strongSelf = weakSelf; + if (!strongSelf) { + return; } - [self->_view show]; + if (!strongSelf->_view) { + strongSelf->_view = [[RCTLogBoxView alloc] initWithFrame:[UIScreen mainScreen].bounds bridge:self->_bridge]; + } + [strongSelf->_view show]; }); } } @@ -103,8 +108,13 @@ RCT_EXPORT_METHOD(show) RCT_EXPORT_METHOD(hide) { if (RCTRedBoxGetEnabled()) { + __weak RCTLogBox *weakSelf = self; dispatch_async(dispatch_get_main_queue(), ^{ - self->_view = nil; + __strong RCTLogBox *strongSelf = weakSelf; + if (!strongSelf) { + return; + } + strongSelf->_view = nil; }); } }