ios – 呈现UIImagePickerController时检测到泄漏

前端之家收集整理的这篇文章主要介绍了ios – 呈现UIImagePickerController时检测到泄漏前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我用来呈现UI ImagePickerController的代码

- (IBAction)takePhoto:(UIButton *)sender {

  if (![UIImagePickerController
          isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

    UIAlertController *alert = [UIAlertController
        alertControllerWithTitle:NSLocalizedString(@"Error",nil)
                         message:NSLocalizedString(@"Device has no camera",nil)
                  preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *ok =
        [UIAlertAction actionWithTitle:NSLocalizedString(@"OK",nil)
                                 style:UIAlertActionStyleDefault
                               handler:nil];
    [alert addAction:ok];
    [self presentViewController:alert animated:YES completion:nil];

  } else {

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.videoQuality = UIImagePickerControllerQualityTypeMedium;

    [self presentViewController:picker animated:YES completion:NULL];
  }
}

目前我运行这个方法(例如点击UIButton)我可以在仪器中看到这个:

Leaks By Backtrace

这就是我所看到的,如果我改为Cycles&根源:

Cycles and Roots

因此,如果我将鼠标悬停在第一次泄漏上,然后按下弹出的箭头,我会得到:

enter image description here

如果我为这个方法打开堆栈跟踪,我看到:

enter image description here

所以主要是系统调用.同样适用于其他泄漏,只是系统调用……所以这是一个bug还是?如果我几次打开和关闭图像选择器,我会得到更多的泄漏,更多……

有人注意到了吗?

解决方法

你需要使UIImagePickerController * picker成为一个强大的属性.因此,该应用程序具有对该选择器的全局引用,您将能够将其解雇.

猜你在找的Xcode相关文章