使用CVOpenGLESTextureCacheCreateTextureFromImage将图像上载到纹理时发生内存泄漏

时间:2014-10-12 09:47:19

标签: ios objective-c memory-leaks opengl-es core-video

我使用Instruments进行了调试,但我找不到它:

    CVPixelBufferRef pixelBuffer;
    CVReturn err = CVPixelBufferCreateWithBytes(kCFAllocatorDefault, IMAGE_WIDTH, IMAGE_HEIGHT, kCVPixelFormatType_32BGRA, _outputFrame.data, 4 * IMAGE_WIDTH, dataReleaseCallback, NULL, NULL, &pixelBuffer);

    if(!pixelBuffer || err) {
      NSLog(@"CVPixelBufferCreateWithBytes failed (error: %d)", err);
      return;
    }

    CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault, _backgroundTextureCache, pixelBuffer, NULL, GL_TEXTURE_2D, GL_RGBA, IMAGE_WIDTH, IMAGE_HEIGHT, GL_BGRA, GL_UNSIGNED_BYTE, 0, &_backgroundTextureRef);
    _backgroundTexture = CVOpenGLESTextureGetName(_backgroundTextureRef);
    [_frameLock unlock];
    glBindTexture(GL_TEXTURE_2D, _backgroundTexture);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

然后在OpenGL绘制方法中,在绘制调用之后:

...
CFRelease(_backgroundTextureRef);
_backgroundTextureRef = NULL;
CVOpenGLESTextureCacheFlush(_backgroundTextureCache, 0);

我尝试手动释放像素缓冲区,但随后dataReleaseCallback的回调CVOpenGLESTextureCacheCreateTextureFromImage失败并显示EXC_BAD_ACCESS。我不知道还有什么可能泄漏到那里。

更新

我评论了回调的主体:

inline void dataReleaseCallback(void *releaseRefCon, const void *baseAddress)
{
//  free((void *)baseAddress);
}

现在我可以致电:

CVPixelBufferRelease(_pixelBuffer);

没有任何错误,内存泄漏是固定的。出现的问题是那次回调的效用是什么?

0 个答案:

没有答案