Lim*_*mon 7 avfoundation swift
如何在Swift中使用"CFRetain(sampleBuffer)"和"CFRelease(sampleBuffer)"?
CFRetain is unavailable: Core Foundation objectes are automatically memory managed.
- (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);
});
}
Run Code Online (Sandbox Code Playgroud)
如果需要在此方法范围之外引用CMSampleBuffer对象,则必须CFRetain它,然后在完成后再发送它.(Apple文件)
根据 苹果文档
内存管理对象
从带注释的 API 返回的 Core Foundation 对象在 Swift 中自动进行内存管理——您不需要自己调用 CFRetain、CFRelease 或 CFAutorelease 函数。
如果你从你自己的 C 函数和 Objective-C 方法返回 Core Foundation 对象,你可以用 CF_RETURNS_RETAINED 或 CF_RETURNS_NOT_RETAINED 宏注释它们以自动插入内存管理调用。您还可以使用 CF_IMPLICIT_BRIDGING_ENABLED 和 CF_IMPLICIT_BRIDGING_DISABLED 宏来包含遵循 Core Foundation 所有权策略命名策略的 C 函数声明,以便从命名推断内存管理。
如果您仅使用不间接返回 Core Foundation 对象的带注释的 API,则可以跳过本节的其余部分。否则,继续学习如何使用非托管 Core Foundation 对象。
| 归档时间: |
|
| 查看次数: |
1603 次 |
| 最近记录: |