How to use "CFRetain (sampleBuffer)" and "CFRelease (sampleBuffer)" in Swift?
CFRetain is unavailable: Core Foundation objectes are automatically memory managed.
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection { [self appendVideoSampleBuffer:sampleBuffer]; } - (void)appendVideoSampleBuffer:(CMSampleBufferRef)sampleBuffer { dispatch_async( _writingQueue, ^{ CFRetain(sampleBuffer); [_videoInput appendSampleBuffer:sampleBuffer]; CFRelease(sampleBuffer); }); }
If you need to reference a CMSampleBuffer object outside the scope of this method, you must CFRetain it and then CFRelease when you are done with it. ( Apple document )
source share