-
Notifications
You must be signed in to change notification settings - Fork 24.8k
[iOS]Fix Alert memory leak #10407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[iOS]Fix Alert memory leak #10407
Conversation
By analyzing the blame information on this pull request, we identified @javache and @dlowder-salesforce to be potential reviewers. |
@littlesome updated the pull request - view changes |
@@ -148,18 +146,19 @@ - (void)invalidate | |||
} else if ([buttonKey isEqualToString:destructiveButtonKey]) { | |||
buttonStyle = UIAlertActionStyleDestructive; | |||
} | |||
__weak UIAlertController* weakAlertController = alertController; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: __weak UIAlertController *weakAlertController = alertController;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just one style nit.
@facebook-github-bot shipit |
@lacker has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
Summary: 1. Using weak container to hold the currently opened alerts. 2. Using weak reference to alertController in action handler block. 3. BTW, remove the unused vars: _alertCallbacks, _alertButtonKeys. Test plan (required) ``` - (void)invalidate { for (UIAlertController *alertController in _alertControllers) { [alertController.presentingViewController dismissViewControllerAnimated:YES completion:nil]; } } ``` Since we use weak container, _alertControllers should only contains the currently opened alerts. I test this way: Put a breakpoint in invalidate, open the UIExplorer play with the 'Alert' & 'AlertIOS' examples, then fire a reload and see if _alertControllers contains the expected values. Closes facebook#10407 Differential Revision: D4078649 Pulled By: lacker fbshipit-source-id: 8509e7e7142379a81d5b28c9067c085bad8bb5cb
Test plan (required)
Since we use weak container, _alertControllers should only contains the currently opened alerts.
I test this way: Put a breakpoint in invalidate, open the UIExplorer play with the 'Alert' & 'AlertIOS' examples, then fire a reload and see if _alertControllers contains the expected values.