5

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:

enter image description here

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?

Fidel
  • 1,173
  • 11
  • 21
  • You're not alone, I can reproduce this on iOS 10.3.3 and Xcode 8.3.3 using similar, minimal code. "Other processes" memory usage increases gradually with each photo taken until all system memory is used up, then the app crashes with a "Lost connection" message and no exception in the app (because the leak appears to be within the UIImageViewController code). – davidgoli Jul 25 '17 at 19:56
  • Related: https://stackoverflow.com/questions/42249570/frequently-camera-capture-crashing-the-app-without-any-clue – davidgoli Jul 25 '17 at 21:21
  • Thanks for the link @davidgoli, I am glad to know that i am not the only one. I can reproduce this issue by simply having an image view on my app. It's crashing anyway after 40-50 pictures are taking. It's very annoying and I am still struggling with this. – Fidel Jul 26 '17 at 20:13

2 Answers2

2

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.

Fidel
  • 1,173
  • 11
  • 21
1

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.

davidgoli
  • 2,436
  • 1
  • 16
  • 13
  • 1
    I heard back from Apple after filing a bug report. They closed my bug report as a duplicate & verified that another, open bug exists for this issue. Since it's under NDA, it's not possible to link to the original bug report here. – davidgoli Aug 11 '17 at 00:42
  • @davidgoli how had you resolved this UIImagePickerController issue with multiple image click issue ? I am facing crash over iOS 10.3 if I get 40-50 images clicked. – Mrunal Dec 03 '18 at 09:42
  • @Mrunal see my link in the original post – davidgoli Dec 05 '18 at 21:35