在captureOutput(didOutputSampleBuffer:_)内调用的dispatch_async(dispatch_get_main_queue())会导致内存压力

时间:2017-08-11 18:23:56

标签: ios avfoundation grand-central-dispatch

我正在使用一个非常标准的设置从captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection connection: AVCaptureConnection!)获取CMSampleBufferRef对象的视频录制应用。我们将样本缓冲区转换为UIImage个对象,并将图像设置为UIImageView。当然,需要在主线程上设置.image UIImageView属性,以便在dispatch_async(dispatch_get_main_queue())块中调用操作。将调用添加到主线程导致didOutputSampleBuffer:内的内存压力导致内存使用量以大约500kb / s的速率增长。

这是复制内存压力的代码示例。

func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection connection: AVCaptureConnection!) {

  dispatch_async(dispatch_get_main_queue()) { 

  }

}

enter image description here

我尝试在dispatch_block_t块中使用可选项,并在操作完成后将其设置为nil。我也尝试使用NSOperationQueue,但同样的问题也出现了。

我在iOS 10.3.2上运行Swift 2.3

0 个答案:

没有答案
相关问题