【发布时间】:2018-04-18 20:36:54
【问题描述】:
我正在尝试弄清楚所有权如何与函数 CVMetalTextureGetTexture 一起使用:
CVMetalTextureRef textureRef;
// ... textureRef is created
id<MTLTexture> texture = CVMetalTextureGetTexture(_textureRef);
CVBufferRelease(textureRef); // Releasing the existing texture
// Is texture still valid here?
释放textureRef后texture还有效吗?如果没有,我可以以某种方式将所有权从textureRef 转移到texture (ARC),这样我就不必在稍后释放texture 时调用CVBufferRelease?
对于 swift 的同样问题:
var texture: MTLTexture
do {
var textureRef: CVMetalTexture
// ... textureRef is created
texture = CVMetalTextureGetTexture(textureRef)!
// end of scope, textureRef is released
}
// Is texture still valid here?
【问题讨论】:
-
你可能想看看这个GitHub Reporsitory的文件
MetalCameraSession.swift。 -
@mschmidt 感谢您的评论!不过,我不能确定这个存储库中的那个人是否正确地完成了所有操作,或者他的代码是否存在内存问题......
标签: objective-c swift automatic-ref-counting core-foundation core-video