Does CIContext memory leak stil exist on iOS 9.2?

When using CIContext with an EAGLContext I get a huge memory leak on iOS 9.2. I've seen reports of this being solved on iOS 9.1 but I cannot confirm that. Has anyone successfully been able to remove the memory leak caused by CIContext drawImage, createCGImage and render on iOS 9.1 or later?


I've tested dropping EAGLContext by using MetalKit and MLKDevice. I've tested using different methods of CIContext like drawImage, createCGImage and render but nothing seem to work.

It is very clear that this is a bug as of iOS 9. Try it out your self by downloading the example app from Apple (see below) and then run the same project on a device with iOS 8.4, then on a device with iOS 9.2 and pay attention to the memory gauge in Xcode.


Download

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


Add this to the APLEAGLView.h:20

@property (strong, nonatomic) CIContext* ciContext;


Replace APLEAGLView.m:118 with this

  [EAGLContext setCurrentContext:_context];
   _ciContext = [CIContext contextWithEAGLContext:_context];


And finaly replace APLEAGLView.m:341-343 with this

  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);

I can confirm this is happening for me too (Broken on 9.2 and working on 8.4). Deleting the CIContext doesn't clear the memory either 😟


I don't know how this keeps getting past Apple's quality control.


Really not sure what to do at this point. I pretty much decided on core image as my technology for filters and effects on still images and video and it would be a lot of work to re-implement everything in OpenGL directly.


Please let me know if anyone finds a workaround.


PS: I filed a Radar: 24850067

I see this memory leak as well. My code has not changed but after installing iOS 9.2 the leak is dramatic.


[CIContext drawImage:inRect:fromRect:] leaks slowly. However if you render on a different dispatch queue it leaks very quickly.

Does CIContext memory leak stil exist on iOS 9.2?
 
 
Q