草庐IT

objective-c - CVMetalTextureGetTexture 所有权?

coder 2023-09-06 原文

我试图弄清楚所有权如何与函数 CVMetalTextureGetTexture 一起工作:

CVMetalTextureRef textureRef;
// ... textureRef is created
id<MTLTexture> texture = CVMetalTextureGetTexture(_textureRef);
CVBufferRelease(textureRef); // Releasing the existing texture
// Is texture still valid here?

释放textureReftexture是否仍然有效?如果没有,我能否以某种方式将所有权从 textureRef 转移到 texture (ARC),这样我以后就不必在 时调用 CVBufferRelease >texture 发布了吗?

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?

最佳答案

这是一个很好的问题,因为这种问题打破了 Create Rule ,但似乎这种方法确实保留了底层对象。我想这条规则不适用于 Core Foundation -> ARC 方法...

可以在this Apple Demo中看到他们确实在将其转换为 id<MTLTexture> 后释放了 ref .他们在更隐含的 Swifty 版本中执行此操作,因此很容易被忽略。

关于objective-c - CVMetalTextureGetTexture 所有权?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47141060/

有关objective-c - CVMetalTextureGetTexture 所有权?的更多相关文章

随机推荐