- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
如何在 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. (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/
我是一名优秀的程序员,十分优秀!