gpt4 book ai didi

swift - 如何在 Swift 中使用 "CFRetain(sampleBuffer)"?

转载 作者:搜寻专家 更新时间:2023-10-30 21:59:26 25 4
gpt4 key购买 nike

如何在 Swift 中使用“CFRetain(sampleBuffer)”和“CFRelease(sampleBuffer)”? enter image description hereCFRetain 不可用: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. (Apple Document)

最佳答案

根据 Apple Doc

内存管理对象

Core Foundation objects returned from annotated APIs are automaticallymemory 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 andObjective-C methods, you can annotate them with either theCF_RETURNS_RETAINED or CF_RETURNS_NOT_RETAINED macro to automaticallyinsert memory management calls. You can also use theCF_IMPLICIT_BRIDGING_ENABLED and CF_IMPLICIT_BRIDGING_DISABLED macrosto enclose C function declarations that follow Core Foundationownership policy naming policy in order to infer memory managementfrom naming.

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

关于swift - 如何在 Swift 中使用 "CFRetain(sampleBuffer)"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38139389/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com