UIImagePickerController在启动后和拍照期间会泄漏内存.拍摄超过100张照片后使应用程序崩溃 [英] UIImagePickerController leaking memory after launch and during taking a picture. Makes app crash after taking more than a 100 pictures

查看:551
本文介绍了UIImagePickerController在启动后和拍照期间会泄漏内存.拍摄超过100张照片后使应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为这个问题苦苦挣扎了好几个星期了.我到处都在网上看过,发现除了这个2个局外人链接之外,没有什么比这个问题更重要的了:

I have been struggling with this issue for weeks now. I have look online all over the place and found nothing close to this issue other than this 2 outsider links:

https://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview/issues/200

https://issues.apache.org/jira/browse/CB-11784

但是那些没有使用相同的环境,也没有解决该问题的实际方法.

But those are not using the same environment and there is no actual solution to the problem.

这是我启动imagePicker并拍照后使用Xcode 8.3拍摄的我的工具的屏幕截图:

Here is a screenshot of my Instrumentals using Xcode 8.3 right after I launch the imagePicker and take a picture:

以下是与imagePicker相关的代码:

Here is the code related to the imagePicker:

      //initializer on my class
      var imagePicker = UIImagePickerController()

      //imagepicker setup on ViewDidLoad()

      imagePicker.delegate = self
      imagePicker.allowsEditing = false
      imagePicker.mediaTypes = [kUTTypeImage as String]

      if UIImagePickerController.isSourceTypeAvailable(.camera) {
          imagePicker.sourceType = .camera

      }
      else {
        print("Sorry this app only supports camera")
      }


      //function to start picker when click on button
      func startPicker(){

        self.present(imagePicker, animated: false, completion: nil)

      }

       //delegate functions

      func imagePickerControllerDidCancel(_ picker: UIImagePickerController)
      {
                imagePicker.dismiss(animated: false, completion: nil)
      }

      func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])
      {

           //display photo on view

           imagePicker.dismiss(animated: false, completion: nil)

      }

这是IOS上的错误,还是可以消除此内存泄漏?

Is this a bug on IOS or is there a away to get rid off this memory leak?

推荐答案

我只想指出,从IOS 12开始,这个问题仍然存在,为了避免崩溃,我不得不使用AVFoundation的Camera.使用AVFoundation,我可以拍摄数百张照片,并且不会发生内存泄漏.

I just want to point out that as of IOS 12 this problem still exists and I had to use the Camera of AVFoundation to avoid the crashing. With AVFoundation I can take hundreds of pictures and no memory leak occurred.

这篇关于UIImagePickerController在启动后和拍照期间会泄漏内存.拍摄超过100张照片后使应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆