imagePickerController在没有任何其他代码的情况下泄漏

时间:2019-03-30 13:30:19

标签: ios swift memory-leaks uiimagepickercontroller

ImagePickerController在我的项目中泄漏,因此我创建了一个测试项目,其中有一个按钮显示imagePickerController。它什么也没有做,但是当我测试这个简单的测试项目是否存在仪器泄漏时,它也会泄漏,它在我展示并关闭imagePickerController几次后发生。我的代码有误吗?还是苹果的代码泄漏了?

以下是一些图片: stack trace graph

class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {

let button = UIButton()
let imagePicker = UIImagePickerController()

override func viewDidLoad() {
    super.viewDidLoad()

    view.backgroundColor = .white
    button.backgroundColor = .black
    button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)

    view.addSubview(button)

    button.translatesAutoresizingMaskIntoConstraints = false

    NSLayoutConstraint.activate([
        button.centerXAnchor.constraint(equalTo: view.centerXAnchor),
        button.centerYAnchor.constraint(equalTo: view.centerYAnchor),
        button.widthAnchor.constraint(equalToConstant: 100),
        button.heightAnchor.constraint(equalToConstant: 100)

        ])
}

@objc func buttonAction () {
    imagePicker.sourceType = UIImagePickerController.SourceType.camera
    imagePicker.allowsEditing = true
    present(imagePicker, animated: true)
}

}

0 个答案:

没有答案