【问题标题】:UIImagePickerController cause Leaks after taking 2 3 pictures in swiftUIImagePickerController 在快速拍摄 2 3 张照片后导致泄漏
【发布时间】:2016-11-18 05:09:56
【问题描述】:

我正在制作相机的自定义视图,其中我正在从图库和相机拍摄照片,照片库工作正常,但相机无法正常工作,我正在使用 UIImagePickerController,拍摄 3 4 张照片后它会导致内存泄漏并关闭应用程序,我正在正确呈现viewcontroller 和dissmissingviewcontroller 但无论如何它都会产生内存泄漏问题,我使用泄漏工具来追踪问题,我发现UIImagePickerController 每次出现时都会创建新实例拍照

       Avfoundation -[AVCapturePhotoOutput init]
       NSSmutableArray Avfoundation -[[AVCapturePhotoOutput init]

请指导我如何解决它?因为我不擅长管理内存泄漏。

编辑: 这是 didfinishdelegate 方法!

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]){

    if let image = info[UIImagePickerControllerOriginalImage] as? UIImage{

        self.delegate?.didFinishTakingPhoto(image)
        picker.dismissViewControllerAnimated(true, completion: { () -> Void in
           self.popMe(false)
        })

} }

    func didFinishTakingPhoto(image: UIImage)
       {
    self.imageView.image = image;
    self.startActivity("", detailMsg: "")
    self.view.userInteractionEnabled = false
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)) { () -> Void in

        if let chokusItem = self.item {
            var size = CGSizeMake(600.0, CGFloat.max)
            if Global.shared.highQualityPhotoEnables {
                size.width = 900.0
            }
            let scaledImage = self.imageView.image!.resizedImageWithContentMode(UIViewContentMode.ScaleAspectFit, bounds: size, interpolationQuality: CGInterpolationQuality.High)
            let thumbSize = CGSizeMake(80.0, CGFloat.max)
            self.thumbImage = self.imageView.image!.resizedImageWithContentMode(UIViewContentMode.ScaleAspectFit, bounds: thumbSize, interpolationQuality: CGInterpolationQuality.High)

            self.photo = PhotoViewModel(image: scaledImage, parent: chokusItem)

            let delay = 0 * Double(NSEC_PER_SEC)
            let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
            dispatch_after(time, dispatch_get_main_queue(), {
                self.imageView.image = scaledImage
                self.stopActivity()
                self.removeCommentTableViews()
                self.removeCommentViews()
                self.view.userInteractionEnabled = true
                self.showPhotoLimitAlertIfRequired()
            })
            if Global.shared.shouldSavePhotoToGallery {

                let assetsLibrary = ALAssetsLibrary()
                assetsLibrary.saveImage(scaledImage, toAlbum: "Inspection Images", completion: { (url, error) -> Void in
                    print("success", terminator: "")
                    }, failure: { (error) -> Void in
                        print("failure", terminator: "")
                })
            }
        }
    }
}

【问题讨论】:

  • 你能把代码贴在 didFinishPickingImage 委托中吗?
  • @ebby94 我已经编辑了我的帖子..

标签: ios swift memory-leaks uiimagepickercontroller


【解决方案1】:

这似乎是 iOS 中的某种错误,但我不确定,在提出自己的问题后,我被指出了这个线程,因为我没有找到这个。

但是,我正在以与您完全不同的方式初始化我的代码,但泄露的对象看起来相同。

我已经对此打开了雷达: https://openradar.appspot.com/29495120

你也可以在这里看到我的问题: https://stackoverflow.com/questions/41111899/avcapturephotooutput-memory-leak-ios

希望这个答案至少能让您在我等待确认时减少浪费时间的头痛。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-09
    • 2012-07-04
    • 2011-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-31
    相关资源
    最近更新 更多