From 1b51cd488a67aedae2d13f7410579fc4691b2b6b Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Mon, 1 Apr 2019 13:41:52 -0700 Subject: [PATCH] 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 --- React/DevSupport/RCTDevMenu.m | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/React/DevSupport/RCTDevMenu.m b/React/DevSupport/RCTDevMenu.m index d631fa5dc75..140be91dd98 100644 --- a/React/DevSupport/RCTDevMenu.m +++ b/React/DevSupport/RCTDevMenu.m @@ -204,6 +204,7 @@ RCT_EXPORT_MODULE() // Add built-in items __weak RCTBridge *bridge = _bridge; __weak RCTDevSettings *devSettings = _bridge.devSettings; + __weak RCTDevMenu *weakSelf = self; [items addObject:[RCTDevMenuItem buttonItemWithTitle:@"Reload" handler:^{ [bridge reload]; @@ -296,7 +297,7 @@ RCT_EXPORT_MODULE() textField.placeholder = @"index"; }]; [alertController addAction:[UIAlertAction actionWithTitle:@"Use bundled JS" style:UIAlertActionStyleDefault handler:^(__unused UIAlertAction *action) { - [self setDefaultJSBundle]; + [weakSelf setDefaultJSBundle]; }]]; [alertController addAction:[UIAlertAction actionWithTitle:@"Use packager location" style:UIAlertActionStyleDefault handler:^(__unused UIAlertAction *action) { NSArray * textfields = alertController.textFields; @@ -308,7 +309,7 @@ RCT_EXPORT_MODULE() bundleRoot = @"index"; } if(ipTextField.text.length == 0 && portTextField.text.length == 0) { - [self setDefaultJSBundle]; + [weakSelf setDefaultJSBundle]; return; } NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; @@ -319,8 +320,11 @@ RCT_EXPORT_MODULE() } [RCTBundleURLProvider sharedSettings].jsLocation = [NSString stringWithFormat:@"%@:%d", ipTextField.text, portNumber.intValue]; - self->_bridge.bundleURL = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:bundleRoot fallbackResource:nil]; - [self->_bridge reload]; + __strong RCTBridge *strongBridge = bridge; + if (strongBridge) { + strongBridge.bundleURL = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:bundleRoot fallbackResource:nil]; + [strongBridge reload]; + } }]]; [alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(__unused UIAlertAction *action) { return;