UIImagePickerController memory leak issue

Hi,


In my application, I am using UIImagePickerController to take the photos, videos, choosing images from gallery and saving them in application document directory. If we launch camera and take picture/videos, app starts terminating without any crash log. For every launch of camera in the application, the RAM consuption is increased and after some time app gets terminated saying "Application terminated due to memory issue". I have observed this memory leak in XCode(10.1) and Instrument tool.



func takePhoto() {

if UIImagePickerController.isSourceTypeAvailable(UIImagePickerController.SourceType.camera) {

self.mediaType = .Photo

let imagePicker = UIImagePickerController()

imagePicker.delegate = self

imagePicker.sourceType = UIImagePickerController.SourceType.camera

imagePicker.allowsEditing = false

imagePicker.hidesBarsOnTap = true

imagePicker.isNavigationBarHidden = true;

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

}

}



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

// Local variable inserted by Swift 4.2 migrator.

let info = convertFromUIImagePickerControllerInfoKeyDictionary(info)

if let image = info[convertFromUIImagePickerControllerInfoKey(UIImagePickerController.InfoKey.originalImage)] {

//Writing the image to document directory

}

picker.dismiss(animated: true, completion: nil)

}



// Helper function inserted by Swift 4.2 migrator.

fileprivate func convertFromUIImagePickerControllerInfoKey(_ input: UIImagePickerController.InfoKey) -> String {

return input.rawValue

}


XCode 10.1

Swift 4.2

iOS version - 10.2.1

Devices RAM - 1GB/2GB

Devices - iPad Pro, iPad Mini

Memoy - 16GB, 64GB, 32GB


Could you please help on this and suggest a better solution

Thanks,

Replies

Are you sure it is a memory leak or a strong reference somewhere that prevents ARC to free memory ?


If you are sure of diagnosis, best would be to file a bug report.

Thank you for the quick response,


In takePhoto function, I am creating a local variable/instance of UIImagePickerController and presenting the picker and after taking picture, dismissing the presented picker. Even after cancel, dismissing the presented picker.


Iam facing this issue after taking 50 to 100 photos/videos and saving them in the document directory. After taking some photos/videos, if we launch the camera, the RAM space is filling and free space is continuously reducing and application crashing.


Please suggest,

Could you show the complete code of the controller where you are creating a local variable/instance of UIImagePickerController ?

Please find the sample project of UIImagePickerController that the same code Iam using in my project. Here also facing the same issue but its allowing me to take around 150 images after that app starts crashing. For every launch of camers, other processes are increasing and free memory is reducing and start crashing.


Uploaded code and screenshot in the github and below is the url.

https://github.com/tharigoppula/UIImagePickerControllerTest.git


Please suggest,