Ios CoreImage的内存泄漏

Ios CoreImage的内存泄漏,ios,memory-leaks,core-image,Ios,Memory Leaks,Core Image,我已经创建了如下模糊图像: //Blur the UIImage CIImage *imageToBlur = [CIImage imageWithCGImage:viewImage.CGImage]; CIFilter *gaussianBlurFilter = [CIFilter filterWithName: @"CIGaussianBlur"]; [gaussianBlurFilter setValue:imageToBlur forKey: @"inputImage"]; [gauss

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

//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(uu CFString const*)

谁能告诉我如何解决这个内存泄漏问题


提前感谢您的帮助。

所有的核心框架都使用C语言,而不是Objective-C。您必须手动进行内存管理,ARC在这方面帮不了您多少忙,除非将一些(免费桥接)引用的所有权从核心转移到Objective-C对象。你真的应该阅读这本书来了解你需要做什么


不过,简而言之,将引用设置为
nil
(在C中应为
NULL
)会导致指针悬空和内存泄漏

问题在于不断的呼叫

[CIContext contextWithOptions:nil]
我建议在类中创建
CIContext
属性:

@property (retain, nonatomic) CIContext *context;
并且只在上下文为nil时实例化它

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

您好,感谢您的快速回复,我将检查文档。您是否也有其他泄漏的对象,或者只有CGImage对象?获取CoreImage和main.m@autoreleasepool{return UIApplicationMain(argc,argv,nil,NSStringFromClass([OpinoAppDelegate class]);}中的内存泄漏。其他泄漏的对象是什么类型的?UIImage?图像视图?或者只有CGImageRef对象泄漏?只有CGImageRef对象泄漏可能是因为上下文对象,这有点奇怪。您创建的唯一CGImageRef似乎已正确发布。CIContext是一个NSObject,应该由ARC处理。我不确定这是否是解决方案。我甚至使用了一处房产也有漏洞。我认为一般的答案是使用@autoreleasepool、CG对象释放等等。