加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – 呈现UIImagePickerController时检测到泄漏

发布时间:2020-12-14 17:25:34 所属栏目:百科 来源:网络整理
导读:这是我用来呈现UI ImagePickerController的代码: - (IBAction)takePhoto:(UIButton *)sender { if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { UIAlertController *alert = [UIAlertController alertCo
这是我用来呈现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成为一个强大的属性.因此,该应用程序具有对该选择器的全局引用,您将能够将其解雇.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读