4 Replies
      Latest reply on Apr 18, 2019 3:00 AM by sudhakar.tharigoppula
      sudhakar.tharigoppula Level 1 Level 1 (0 points)

        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,