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

如何在Swift中使用“CFRetain(sampleBuffer)”?,第1张

概述如何在 Swift中使用“CFRetain(sampleBuffer)”和“CFRelease(sampleBuffer)”? CFRetain不可用:Core Foundation目标是自动内存管理的. - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)s 如何在 Swift中使用“CFRetain(sampleBuffer)”和“CFRelease(sampleBuffer)”?


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.

总结

以上是内存溢出为你收集整理的如何在Swift中使用“CFRetain(sampleBuffer)”?全部内容,希望文章能够帮你解决如何在Swift中使用“CFRetain(sampleBuffer)”?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1017769.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存