iOS 8只有使用UIAlertController或UIActionSheet的内存泄漏

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

showCameraAction在按下button时被调用。 我已经从委托方法中删除了所有的内容,并仍然在下面的情况下泄漏。 我是否以某种方式使用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]; 

泄漏工具的截图

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

我会build议在iOS8中使用“UIAlertController”。 并从提供的控制器中closuresalertController对象,同时通过“UIAlertAction”块触发任何事件。

 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]; 

这是一个iOS错误。

请参阅Apple Bug Reporter问题21005708 ,ARC下的UIAlertController中的内存泄漏。

这不是答案,但更多的泄漏证据,超过了评论。 可以帮助find一个解决scheme或解决方法。 泄漏似乎是在iPad 3 / Retina上的设备特定!

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

另见: https : //devforums.apple.com/message/1099577#1099577

  • LEAKY设备:iPad 3(A1416),iPad Air Simulator
  • 良好的设备:iPhone 6 iOS 8.1.3,iPhone 4s与iOS 8.1.2

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

iPad视网膜模拟器的iOS 8.1和真正的iPad泄漏 // 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. // 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和真正的iPad,解雇没有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 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

我build议切换到UIAlertController 。 UIActionSheet在iOS 8中不推荐使用,所以你可以尝试一下,看看是否还有泄漏