UIImagePickerController leaking memory after launc

2019-02-14 19:48发布

问题:

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.