CIContext,iOS 9和内存问题

时间:2015-10-06 23:58:45

标签: ios iphone memory avfoundation ios9

所以我最近将iOS更新为9.0.2。 我一直在使用Apple的示例RosyWriter来使用CIFilter和CIContext捕获和过滤视频帧。 它在iOS 7和8中运行良好。 这一切都在iOS 9中崩溃了。

现在RosyWriter中的内存报告和我的应用程序如下所示: enter image description here

最终应用程序崩溃了。

我调用 [_ ciContext render:toCVPixelBuffer:bounds:colorSpace:]; imageWithCVPixelBuffer 。当我调用这两种方法时,看起来CIContext有内部内存泄漏。

花了大约4天后,我发现如果我每次想要渲染缓冲区并在之后释放它而创建一个新的CIContext实例 - 这会使内存保持不变。但这不是一个解决方案,因为这样做太昂贵了。

其他人有这个问题吗?有没有解决的办法?

感谢。

3 个答案:

答案 0 :(得分:1)

我可以确认iOS 9.2上仍存在此内存泄漏。 (我也发布在Apple Developer Forum上。)

我在iOS 9.2上遇到了相同的内存泄漏。我已经通过使用MetalKit和MLKDevice测试了丢弃EAGLContext。我已经测试过使用CIContext的不同方法,比如drawImage,createCGImage和render,但似乎没什么用。

很明显,这是iOS 9中的一个错误。通过从Apple下载示例应用程序(见下文)尝试自己,然后在iOS 8.4设备上运行相同项目,然后在设备上运行使用iOS 9.2并注意Xcode中的内存量表。

下载 https://developer.apple.com/library/ios/samplecode/AVBasicVideoOutput/Introduction/Intro.html#//apple_ref/doc/uid/DTS40013109

将其添加到APLEAGLView.h:20

 @property (strong, nonatomic) CIContext* ciContext;

用此

替换APLEAGLView.m:118
[EAGLContext setCurrentContext:_context];
 _ciContext = [CIContext contextWithEAGLContext:_context];

最后用这个

替换APLEAGLView.m:341-343
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);  

    @autoreleasepool  
    {  
        CIImage* sourceImage = [CIImage imageWithCVPixelBuffer:pixelBuffer];  
        CIFilter* filter = [CIFilter filterWithName:@"CIGaussianBlur" keysAndValues:kCIInputImageKey, sourceImage, nil];  
        CIImage* filteredImage = filter.outputImage;  

        [_ciContext render:filteredImage toCVPixelBuffer:pixelBuffer];  
    }  

  glBindRenderbuffer(GL_RENDERBUFFER, _colorBufferHandle);  

答案 1 :(得分:0)

使用上下文后,只需使用下面的代码

context = [CIContext contextWithOptions:nil];

并发布CGImageRef对象

 CGImageRelease(<CGImageRef IMAGE OBJECT>);

答案 2 :(得分:-1)

Krafter,

您在编写自定义过滤器吗?我发现dod在iOS 9中的工作方式不同。

看起来如果dod.extent.origin.x和dod.extent.origin.y不接近存储为双精度的整数(例如31.0,333.0),那么输出图像的extent.size将是( dod.extent.size.width + 1.0,dod.extent.size.height + 1.0)。在iOS 9.0之前,输出图像的extent.size始终是(dod.extent.size)。所以,如果(你通过自定义CIFilter反复循环播放相同的图像&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp运行,这可能会像你一样产生一个内存配置文件。}

我认为这是iOS 9中的一个错误,因为输出图像的大小应始终与dod的大小相匹配。

我的设置:iOS v9.2,iPhone 5C和iPad 2,Xcode 7.2,Obj-C