首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIAlertController或UIActionSheet中仅有iOS 8内存泄漏

UIAlertController或UIActionSheet中仅有iOS 8内存泄漏
EN

Stack Overflow用户
提问于 2014-10-08 08:04:57
回答 4查看 4.9K关注 0票数 9

当我使用UIActionSheet或UIAlertController执行以下操作时,我发现模拟器中的iOS 8中存在内存泄漏。UIActionSheet在iOS8中使用UIAlertController,所以问题是相关的。

当按钮被按下时,showCameraAction被调用。我已经从委托方法中删除了所有内容,但在下面所示的情况下仍然会出现泄漏。我是否以某种不应该的方式使用了UIActionSheet?如果您能帮助我解决这个问题,我将不胜感激。相同的代码与IOS 7(在模拟器中)没有泄漏。

代码语言:javascript
复制
-(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
}

//为空

代码语言:javascript
复制
 - (void)actionSheet:(UIActionSheet *)actionSheet
 clickedButtonAtIndex:(NSInteger)buttonIndex {
 }

我也尝试了UIAlertController,结果相同:

代码语言:javascript
复制
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];

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

EN

回答 4

Stack Overflow用户

发布于 2015-07-13 20:22:18

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

代码语言:javascript
复制
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];
票数 5
EN

Stack Overflow用户

发布于 2015-05-19 05:15:35

这是一个iOS错误。

请参阅Apple Bug Reporter issue 21005708,Memory leak in UIAlertController under ARC。

票数 4
EN

Stack Overflow用户

发布于 2015-02-05 20:52:36

这不是答案,但更多的证据证明了泄漏,这超过了评论。希望它有助于找到解决方案或变通方法。泄漏似乎是特定于iPad 3/Retina的设备!

我自己做了一些测试,通过覆盖视图控制器的保留和释放来显示iOS 8.x中的泄漏

另请参阅:https://devforums.apple.com/message/1099577#1099577

  • 泄漏设备: iPad 3 (A1416)、iPad空气模拟器
  • GOOD设备: iPhone 6 iOS 8.1.3、iPhone 4s iOS 8.1.2

AGC是视图控制器。正确的保留计数应为2。

iPad视网膜模拟器iOS 8.1和real iPad LEAK // second run ... this time with LEAK by selecting an option 12:56:50.929 SimplySolitaire[27643:473670] >>> WILL actionSheet showInView: retain = 2 12:56:50.930 SimplySolitaire[27643:473670] AGC retain == 3 12:56:50.950 SimplySolitaire[27643:473670] AGC retain == 4 12:56:50.951 SimplySolitaire[27643:473670] AGC retain == 5 12:56:50.951 SimplySolitaire[27643:473670] AGC retain == 6 12:56:50.951 SimplySolitaire[27643:473670] <<< DID actionSheet showInView: retain = 6 12:56:50.998 SimplySolitaire[27643:473670] AGC release = 5 12:56:51.042 SimplySolitaire[27643:473670] AGC release = 4 12:56:51.042 SimplySolitaire[27643:473670] AGC release = 3 // USER dismisses the action sheet with tapping a button (delegate is nil) 12:56:53.257 SimplySolitaire[27643:473670] AGC retain == 4 12:56:53.257 SimplySolitaire[27643:473670] AGC retain == 5 12:56:53.258 SimplySolitaire[27643:473670] AGC retain == 6 12:56:53.258 SimplySolitaire[27643:473670] AGC retain == 7 12:56:53.258 SimplySolitaire[27643:473670] AGC release = 6 12:56:53.259 SimplySolitaire[27643:473670] AGC release = 5 12:56:53.612 SimplySolitaire[27643:473670] AGC release = 4 12:56:53.612 SimplySolitaire[27643:473670] AGC release = 3 // <<<<<<<<<< LEAK should be 2 // the last release is missing, but only iOS system code has executed.

iPad视网膜模拟器iOS 8.1和real iPad,dismiss LEAK 12:54:54.757 SimplySolitaire[27643:473670] >>> WILL actionSheet showInView: retain = 2 12:54:54.758 SimplySolitaire[27643:473670] AGC retain == 3 12:54:54.798 SimplySolitaire[27643:473670] AGC retain == 4 12:54:54.798 SimplySolitaire[27643:473670] AGC retain == 5 12:54:54.798 SimplySolitaire[27643:473670] AGC retain == 6 12:54:54.798 SimplySolitaire[27643:473670] <<< DID actionSheet showInView: retain = 6 12:54:54.845 SimplySolitaire[27643:473670] AGC release = 5 12:54:54.891 SimplySolitaire[27643:473670] AGC release = 4 12:54:54.891 SimplySolitaire[27643:473670] AGC release = 3 // NOW ... dismiss the action sheet without selection (delegate is nil) 12:55:05.643 SimplySolitaire[27643:473670] AGC retain == 4 12:55:05.644 SimplySolitaire[27643:473670] AGC retain == 5 12:55:05.644 SimplySolitaire[27643:473670] AGC retain == 6 12:55:05.644 SimplySolitaire[27643:473670] AGC retain == 7 12:55:05.645 SimplySolitaire[27643:473670] AGC release = 6 12:55:05.645 SimplySolitaire[27643:473670] AGC release = 5 12:55:05.996 SimplySolitaire[27643:473670] AGC release = 4 12:55:05.997 SimplySolitaire[27643:473670] AGC release = 3 12:55:05.997 SimplySolitaire[27643:473670] AGC release = 2 // this is a correct retain of 2

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26247221

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档