objective-c – CVMetalTextureGetTexture ownerhsip?
发布时间:2020-12-16 07:22:15 所属栏目:百科 来源:网络整理
导读:我试图弄清楚所有权如何与函数CVMetalTextureGetTexture一起使用: CVMetalTextureRef textureRef;// ... textureRef is createdidMTLTexture texture = CVMetalTextureGetTexture(_textureRef);CVBufferRelease(textureRef); // Releasing the existing tex
我试图弄清楚所有权如何与函数CVMetalTextureGetTexture一起使用:
CVMetalTextureRef textureRef; // ... textureRef is created id<MTLTexture> texture = CVMetalTextureGetTexture(_textureRef); CVBufferRelease(textureRef); // Releasing the existing texture // Is texture still valid here? 释放textureRef后纹理是否仍然有效?如果没有,我可以以某种方式将所有权从textureRef转移到纹理(ARC),所以我不必在以后释放纹理时调用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? 解决方法
在我看到你的问题之前,我们还做了另一个实验:
在循环中,从CVPixelBuffer创建的CVMetalTextureRef来自Camera. static void *texturePtr; /** AVCaptureVideoDataOutputSampleBufferDelegate,as a loop */ { CVMetalTextureRef textureRef; // ... textureRef is created id<MTLTexture> texture = CVMetalTextureGetTexture(_textureRef); CVBufferRelease(textureRef); // Releasing the existing texture texturePtr= (__bridge_retained void*)texture; // no releasing the texturePtr // (__bridge_transfer id<MTLTexture>)texturePtr; } 我发现我没有释放texturePtr,但仍然没有发生内存泄漏.更重要的是,texturePtr在某个时候和我们用新的var替换之前是有效的.所以我想也许这与你的问题有关.我的回答更像是一个不是答案的争论. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |