CoreImage的内存泄漏

我已经创build了如下的模糊图像:

//Blur the UIImage CIImage *imageToBlur = [CIImage imageWithCGImage:viewImage.CGImage]; CIFilter *gaussianBlurFilter = [CIFilter filterWithName: @"CIGaussianBlur"]; [gaussianBlurFilter setValue:imageToBlur forKey: @"inputImage"]; [gaussianBlurFilter setValue:[NSNumber numberWithFloat: 2] forKey: @"inputRadius"]; CIImage *resultImage = [gaussianBlurFilter valueForKey: @"outputImage"]; CIImage *finalImage = [resultImage imageByCroppingToRect:CGRectMake(0, 10, self.view.bounds.size.width, self.view.bounds.size.height)]; //create UIImage from filtered image UIImage *blurrredImage = [[UIImage alloc] initWithCIImage:finalImage]; CIFilter *colorMatrixFilter = [CIFilter filterWithName:@"CIColorMatrix"]; [colorMatrixFilter setDefaults]; [colorMatrixFilter setValue:finalImage forKey:kCIInputImageKey]; [colorMatrixFilter setValue:[CIVector vectorWithX:0.25 Y:0 Z:0 W:0] forKey:@"inputRVector"]; [colorMatrixFilter setValue:[CIVector vectorWithX:0 Y:0.35 Z:0 W:0] forKey:@"inputGVector"]; [colorMatrixFilter setValue:[CIVector vectorWithX:0 Y:0 Z:0.4 W:0] forKey:@"inputBVector"]; [colorMatrixFilter setValue:[CIVector vectorWithX:0 Y:0 Z:0 W:1] forKey:@"inputAVector"]; // Get the output image recipe CIImage *outputImage = [colorMatrixFilter outputImage]; // Create the context and instruct CoreImage to draw the output image recipe into a CGImage CIContext *context = [CIContext contextWithOptions:nil]; CGImageRef cgimg = [context createCGImage:outputImage fromRect:[outputImage extent]]; blurrredImage = [UIImage imageWithCGImage:cgimg]; CGImageRelease(cgimg); //Place the UIImage in a UIImageView UIImageView *newView = [[UIImageView alloc] initWithFrame:self.view.bounds]; newView.image = blurrredImage; //insert blur UIImageView below transparent view inside the blur image container [blurContainerView insertSubview:newView belowSubview:transparentView]; 

我已经发布了CGImageRef,但仍然在内存泄漏

 CGImageRef cgimg = [context createCGImage:outputImage fromRect:[outputImage extent]]; 

我也提到所有其他相关的问题,并执行提供的答案仍然是内存泄漏

使用@autoreleasepool {}并尝试将对象设置为nil

 context = nil; outputImage = nil; gaussianBlurFilter = nil; viewImage = nil; 

之前

 CGImageRelease(cgimg); 

它仍然显示内存泄漏和描述如下。 ARC开启,iOS版本是6.1和7

负责任的图书馆是:CoreImage负责任的调用者是:CI :: GLESContext :: program_for_name(__ CFString const *)

任何人都可以请build议我如何解决这个内存泄漏?

我在这里先向您的帮助表示感谢。

所有的核心框架都使用C语言,而不是Objective-C。 您必须手动进行内存pipe理,除非将某些(免费桥接)引用的所有权从Core转移到Objective-C对象,否则ARC不会帮助您。 你真的应该阅读苹果文档 ,了解你需要做什么。

简而言之,设置对nil的引用(在C中应该是NULL )会给你带来一个悬而未决的指针和内存泄漏。

问题将是不断的呼吁

 [CIContext contextWithOptions:nil] 

我build议在你的课堂上创build一个CIContext的属性:

 @property (retain, nonatomic) CIContext *context; 

只有当你的上下文是零时才实例化它

 if( self.context == nil ) { self.context = [CIContext contextWithOptions:nil]; }