When using CIContext with EAGLContext, I get a huge memory leak on iOS 9.2. I saw messages about this that were resolved on iOS 9.1, but I can’t confirm this. Has anyone successfully removed a memory leak caused by CIContext drawImage, createCGImage, and rendering on iOS 9.1 or later?
See this question at the Apple Developer Forum
I tested the EAGLContext reset with MetalKit and MLKDevice. I tested various CIContext methods like drawImage, createCGImage and rendering, but nothing works.
It is very clear that this is a bug with iOS 9.2. Try it yourself by downloading the sample application from Apple (see below), and then run the same project on the device with iOS 8.4 and then on the device with iOS 9.2 and pay attention to the memory pressure gauge in Xcode.
Download https://developer.apple.com/library/ios/samplecode/AVBasicVideoOutput/Introduction/Intro.html#//apple_ref/doc/uid/DTS40013109
Add this to APLEAGLView.h: 20
@property (strong, nonatomic) CIContext* ciContext;
Replace APLEAGLView.m: 118 with this
[EAGLContext setCurrentContext:_context];
_ciContext = [CIContext contextWithEAGLContext:_context];
And finally 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);