当我使用UIActionSheet或UIAlertController执行以下操作时,我发现模拟器中的iOS 8中存在内存泄漏。UIActionSheet在iOS8中使用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
}//为空
- (void)actionSheet:(UIActionSheet *)actionSheet
clickedButtonAtIndex:(NSInteger)buttonIndex {
}我也尝试了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];
带有trace的屏幕截图:https://www.dropbox.com/l/FmnTCd0PvVhuu16BVHZo7p
发布于 2015-07-13 20:22:18
我建议在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];发布于 2015-05-19 05:15:35
这是一个iOS错误。
请参阅Apple Bug Reporter issue 21005708,Memory leak in UIAlertController under ARC。
发布于 2015-02-05 20:52:36
这不是答案,但更多的证据证明了泄漏,这超过了评论。希望它有助于找到解决方案或变通方法。泄漏似乎是特定于iPad 3/Retina的设备!
我自己做了一些测试,通过覆盖视图控制器的保留和释放来显示iOS 8.x中的泄漏
另请参阅:https://devforums.apple.com/message/1099577#1099577
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
https://stackoverflow.com/questions/26247221
复制相似问题