微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何在 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.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐