在我的应用程序中,我正在使用UIImagePickerController拍摄照片,视频,从图库中选择图像并将它们保存在应用程序文档目录中。如果我们启动相机并拍摄照片/录像,则应用程序开始终止,而没有任何崩溃日志。对于应用程序中每次启动相机,都会增加RAM消耗,并且在一段时间后应用程序终止时会显示“应用程序由于内存问题而终止”。我已经在XCode(10.1)和Instrument工具中观察到了这种内存泄漏。
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)
}
// Swift 4.2迁移器插入的辅助函数。
fileprivate func convertFromUIImagePickerControllerInfoKeyDictionary(_ input: [UIImagePickerController.InfoKey: Any]) -> [String: Any] {
return Dictionary(uniqueKeysWithValues: input.map {key, value in (key.rawValue, value)})
}
// Swift 4.2迁移器插入的辅助函数。
fileprivate func convertFromUIImagePickerControllerInfoKey(_ input: UIImagePickerController.InfoKey) -> String {
return input.rawValue
}
XCode 10.1 斯威夫特4.2 iOS版本-10.2.1 装置RAM-1GB / 2GB 设备-iPad Pro,iPad Mini 备忘录-16GB,64GB,32GB
请您提供帮助并提出更好的解决方案
谢谢
答案 0 :(得分:0)
我遇到了同样的问题,并降落在这里。您解决了这个问题吗?
似乎很久以前就有人了。我尝试过,似乎有帮助:
App Terminated due to Memory Pressure when using camera in iOS 7