UIImagePickerController leaking memory after launch and during taking a picture. Makes app crash after taking more than a 100 pictures

不打扰是莪最后的温柔 提交于 2019-12-19 03:13:28

问题


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.

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

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)

      }

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


回答1:


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.




回答2:


I had this problem as well. It appears to be a known bug in UIImagePickerController.

I created a minimal repro app here: https://github.com/davidgoli/UIImagePickerLeakTest

I solved it by implementing my own camera controller using https://github.com/imaginary-cloud/CameraManager.



来源:https://stackoverflow.com/questions/44931452/uiimagepickercontroller-leaking-memory-after-launch-and-during-taking-a-picture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!