2016-11-18 61 views
1

我正在製作相機的自定義視圖,其中我從相冊和照相機拍攝照片,相冊工作正常,但相機無法正常工作,我是使用UIImagePickerController它,拍攝3 4張圖片後,它會導致內存泄漏,並關閉應用程序,我正確呈現viewcontroller和dissmissingviewcontroller,但它創建內存泄漏問題無論如何,我用泄漏儀器追查問題,我發現UIImagePickerController creats新實例每次出現拍照時UIImagePickerController導致迅速拍攝2張3張照片後發生泄漏

 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: "") 
       }) 
      } 
     } 
    } 
} 
+0

你可以在didFinishPickingImage委託中發佈代碼嗎? – ebby94

+0

@ ebby94我編輯了我的帖子.. –

回答

0

這似乎是某種iOS中的bug,我不知道但是,我得到指出此主題做我自己的問題後,因爲我沒有」找到這個。

但是,我以與你完全不同的方式初始化我的代碼,但泄漏的對象看起來是相同的。

我已經開了一個雷達來此上: https://openradar.appspot.com/29495120

您還可以看看我的問題在這裏: https://stackoverflow.com/questions/41111899/avcapturephotooutput-memory-leak-ios

希望這個答案ATLEAST給你一些不太頭痛浪費時間,而我在等待確認。