Skip to content

Commit 1b51cd4

Browse files
JoshuaGrossfacebook-github-bot
authored andcommitted
Fix retain cycle in RCTDevMenu
Summary: A retain-cycle regression was added by D14162776 and detected here: T41208740. Fix should be trivial. Reviewed By: shergin Differential Revision: D14709784 fbshipit-source-id: bad6ab31a5170e9320c4432cbd20d02ec6164f38
1 parent 2a80a42 commit 1b51cd4

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

React/DevSupport/RCTDevMenu.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ - (void)setDefaultJSBundle {
204204
// Add built-in items
205205
__weak RCTBridge *bridge = _bridge;
206206
__weak RCTDevSettings *devSettings = _bridge.devSettings;
207+
__weak RCTDevMenu *weakSelf = self;
207208

208209
[items addObject:[RCTDevMenuItem buttonItemWithTitle:@"Reload" handler:^{
209210
[bridge reload];
@@ -296,7 +297,7 @@ - (void)setDefaultJSBundle {
296297
textField.placeholder = @"index";
297298
}];
298299
[alertController addAction:[UIAlertAction actionWithTitle:@"Use bundled JS" style:UIAlertActionStyleDefault handler:^(__unused UIAlertAction *action) {
299-
[self setDefaultJSBundle];
300+
[weakSelf setDefaultJSBundle];
300301
}]];
301302
[alertController addAction:[UIAlertAction actionWithTitle:@"Use packager location" style:UIAlertActionStyleDefault handler:^(__unused UIAlertAction *action) {
302303
NSArray * textfields = alertController.textFields;
@@ -308,7 +309,7 @@ - (void)setDefaultJSBundle {
308309
bundleRoot = @"index";
309310
}
310311
if(ipTextField.text.length == 0 && portTextField.text.length == 0) {
311-
[self setDefaultJSBundle];
312+
[weakSelf setDefaultJSBundle];
312313
return;
313314
}
314315
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
@@ -319,8 +320,11 @@ - (void)setDefaultJSBundle {
319320
}
320321
[RCTBundleURLProvider sharedSettings].jsLocation = [NSString stringWithFormat:@"%@:%d",
321322
ipTextField.text, portNumber.intValue];
322-
self->_bridge.bundleURL = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:bundleRoot fallbackResource:nil];
323-
[self->_bridge reload];
323+
__strong RCTBridge *strongBridge = bridge;
324+
if (strongBridge) {
325+
strongBridge.bundleURL = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:bundleRoot fallbackResource:nil];
326+
[strongBridge reload];
327+
}
324328
}]];
325329
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(__unused UIAlertAction *action) {
326330
return;

0 commit comments

Comments
 (0)