Reputation: 35
I am using ios 5 with ARc enable. so in the following example I'm getting the memory leak warning...but since using ARC , i cant use autorelease. Please any suggestion anyone?
-(void)coreImageEffect{
CIImage *inputImage = [[CIImage alloc] initWithImage:blurImage.image];
CIFilter *hueAdjust = [CIFilter filterWithName:@"CIHueAdjust"];
[hueAdjust setDefaults];
[hueAdjust setValue:inputImage forKey:@"inputImage"];
[hueAdjust setValue:[NSNumber numberWithFloat: 3.4f]
forKey:@"inputAngle"];
CIImage *outputImage = [hueAdjust valueForKey:@"outputImage"];
CIContext *context = [CIContext contextWithOptions:nil];
blurImage.image = [UIImage imageWithCGImage:
[context createCGImage:outputImage
fromRect:outputImage.extent]];
}
I cannot use [CIContext Autorelease]
;
the problem is showing CIContext "Method returns a core foundation object with a +1 retain count"
Please suggest.
Upvotes: 1
Views: 2741
Reputation: 523444
-createCGImage:…
returns a Core Graphics object which is not an Objective-C object and will not be managed by ARC. So you have to CGImageRelease it manually:
CGImageRef cgImage = [context createCGImage:outputImage
fromRect:outputImage.extent];
blurImage.image = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);
but why not use +imageWithCIImage:
directly?
blurImage.image = [UIImage imageWithCIImage:outputImage];
Upvotes: 11