加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何在Swift中使用“CFRetain(sampleBuffer)”?

发布时间:2020-12-14 04:59:51 所属栏目:百科 来源:网络整理
导读:如何在 Swift中使用“CFRetain(sampleBuffer)”和“CFRelease(sampleBuffer)”? CFRetain不可用:Core Foundation目标是自动内存管理的. - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer f
如何在 Swift中使用“CFRetain(sampleBuffer)”和“CFRelease(sampleBuffer)”?

enter image description here


CFRetain不可用:Core Foundation目标是自动内存管理的.

- (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 the CMSampleBuffer object outside of the scope of this method,you must CFRetain it and then CFRelease it when you are finished with it.
(07001)

解决方法

根据 Apple Doc

内存管理对象

Core Foundation objects returned from annotated APIs are automatically
memory managed in Swift—you do not need to invoke the CFRetain,
CFRelease,or CFAutorelease functions yourself.

If you return Core Foundation objects from your own C functions and
Objective-C methods,you can annotate them with either the
CF_RETURNS_RETAINED or CF_RETURNS_NOT_RETAINED macro to automatically
insert memory management calls. You can also use the
CF_IMPLICIT_BRIDGING_ENABLED and CF_IMPLICIT_BRIDGING_DISABLED macros
to enclose C function declarations that follow Core Foundation
ownership policy naming policy in order to infer memory management
from naming.

If you use only annotated APIs that do not indirectly return Core Foundation objects,you can skip the rest of this section. Otherwise,continue on to learn about working with unmanaged Core Foundation objects.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读