iOS 8仅使用UIAlertController或UIActionSheet进行内存泄漏

Pra*_*era 9 memory-leaks uiactionsheet ios ios8 uialertcontroller

当我使用UIActionSheet或UIAlertController执行以下操作时,我在模拟器中看到iOS 8中的内存泄漏.UIActionSheet在IOS 8中使用UIAlertController,因此问题是相关的.

按下按钮时会调用showCameraAction.我已从委托方法中删除了所有内容,但在下面显示的情况下仍然会出现泄漏.我是否以某种方式使用UIActionSheet,我不应该这样做?我将非常感谢您解决此问题的任何帮助.相同的代码与IOS 7没有泄漏(在模拟器中).

-(IBAction)showCameraAction:(id)sender
{

UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:@"Photo From:"
                                                         delegate:self
                                                cancelButtonTitle:@"Cancel"
                                           destructiveButtonTitle:nil
                                                otherButtonTitles:@"Phone", @"Flickr", nil];

[actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];
//also tried  just showInView: self.view
}
Run Code Online (Sandbox Code Playgroud)

//空

 - (void)actionSheet:(UIActionSheet *)actionSheet
 clickedButtonAtIndex:(NSInteger)buttonIndex {
 }
Run Code Online (Sandbox Code Playgroud)

也尝试使用UIAlertController,结果相同:

UIAlertController *alertController = [UIAlertController
                                      alertControllerWithTitle:@"Photo From:"
                                      message:@""
                                      preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *phoneAction = [UIAlertAction
                               actionWithTitle:NSLocalizedString(@"Phone", @"Phone action")
                               style:UIAlertActionStyleCancel
                               handler:^(UIAlertAction *action)
                               {
                                   NSLog(@"Phone action");
                               }];

UIAlertAction *flickrAction = [UIAlertAction
                           actionWithTitle:NSLocalizedString(@"Flickr", @"Flickr action")
                           style:UIAlertActionStyleDefault
                           handler:^(UIAlertAction *action)
                           {
                               NSLog(@"Flickr action");
                           }];

[alertController addAction:phoneAction];
[alertController addAction:flickrAction];


[self presentViewController:alertController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

泄漏工具截图

带有跟踪的屏幕截图:https://www.dropbox.com/l/FmnTCd0PvVhuu16BVHZo7p

pab*_*jan 5

我建议在iOS8中使用"UIAlertController".并通过"UIAlertAction"块触发任何事件,从呈现的控制器中解除alertController对象.

UIAlertController  *alertController = [UIAlertController alertControllerWithTitle:@"title"
message:@"message"
preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction  *alertAction = [UIAlertAction actionWithTitle:@"actionTitle"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
//Do ur stuff
[alertController dismissViewControllerAnimated:YES
                                    completion:NULL];
}];
[alertController addAction:alertAction];
[self presentViewController:alertController
                       animated:YES
                     completion:NULL];
Run Code Online (Sandbox Code Playgroud)


Phi*_*lip -1

我建议切换到UIAlertController。UIActionSheet 在 iOS 8 中已被弃用,因此您可以尝试一下,看看是否仍然存在泄漏

  • 确认使用 UIAlertController 显示相同的内存泄漏。 (2认同)