小编Ali*_*per的帖子

使用Vision在调度队列中CVPixelBuffer的内存泄漏

我在捕获管道中使用渲染器类来为视频添加CI过滤器.在渲染器的copyRenderedPixelBuffer中,我还想复制像素缓冲区并将其发送到Vision以检测面部标记.

我使用串行调度队列为Vision创建了一个单例.问题是,一旦我添加了调度队列,pixelBuffer就不会从内存中释放出来 - 因此会出现大量泄漏(即使像素缓冲区在objc代码中释放).随着调度队列静音,内存泄漏消失(但由于Vision功能,视频预览存在大量视频延迟).

任何帮助非常感谢!

- (CVPixelBufferRef)copyRenderedPixelBuffer:(CVPixelBufferRef)pixelBuffer
{
    OSStatus err = noErr;
    CVPixelBufferRef renderedOutputPixelBuffer = NULL;

    CVPixelBufferRef visionOutputPixelBuffer;

    CIImage *sourceImage = nil;

    err = CVPixelBufferPoolCreatePixelBuffer( kCFAllocatorDefault, _bufferPool, &renderedOutputPixelBuffer );
    if ( err ) {
        NSLog(@"Cannot obtain a pixel buffer from the buffer pool (%d)", (int)err );
        goto bail;
    }

    err = CVPixelBufferPoolCreatePixelBuffer( kCFAllocatorDefault, _bufferPool, &visionOutputPixelBuffer );
    if ( err ) {
        NSLog(@"Cannot obtain a pixel buffer from the buffer pool (%d)", (int)err );

    }

    // Vision

    CVPixelBufferLockBaseAddress(pixelBuffer, 0);
    int bufferHeight …
Run Code Online (Sandbox Code Playgroud)

memory-leaks grand-central-dispatch swift cvpixelbuffer apple-vision

5
推荐指数
0
解决办法
392
查看次数