在相机模式下使用UIImagePickerController时内存泄漏

时间:2016-12-14 15:15:27

标签: swift memory-leaks uiimagepickercontroller ios10 photolibrary

这是一个简单的单一视图,单个ViewController测试应用。此应用在ViewController中有一个按钮。访问PhotoLibrary并未显示任何泄漏,但camera在显示时会显示一些泄漏,在解除时会显示更多泄漏。

这是代码:

import UIKit

class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

    let pickerCntrl = UIImagePickerController()

    override func viewDidLoad() {
        super.viewDidLoad()
        pickerCntrl.delegate = self
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    @IBAction func takePic(_ sender: Any) {
        pickerCntrl.sourceType = UIImagePickerControllerSourceType.camera
        pickerCntrl.cameraCaptureMode = .photo
        pickerCntrl.allowsEditing = true
        if (UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera)){
            self.present(pickerCntrl, animated: true, completion: nil)
        }
    }

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
//        let editedCapture = info[UIImagePickerControllerEditedImage] as! UIImage?
//        let origCapture = info[UIImagePickerControllerOriginalImage] as! UIImage?
        self.dismiss(animated: true, completion: nil)
    }

    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
        self.dismiss(animated: true, completion: nil)
    }
}

ScreenShot: enter image description here

0 个答案:

没有答案