1

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.

Alex Terente
  • 12,006
  • 5
  • 51
  • 71
Ranajoy Roy
  • 35
  • 1
  • 9

1 Answers1

11

-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];
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
  • one more question Kenny: I want to send my Iphone app to some of my frnds for testing on their simulator, before i upload my project to itunes market. How can i do so? i have ios 5, xcode 4.2 There seems to be no option in this xcode through which i can send the .ipa file. Someone also said me that adhoc distribution is the only obtion, but i believe, there's a easier way to do the same. – Ranajoy Roy Dec 28 '11 at 05:50
  • @RanajoyRoy: You could send them the source code if you don't want to go through Ad Hoc. For .ipa, see http://stackoverflow.com/questions/5265292/xcode-4-create-ipa-file-instead-of-xcarchive. – kennytm Dec 28 '11 at 07:08
  • @RanajoyRoy if KennyTM's answer solved your problem, you should accept his answer buy clicking the √. – clozach Jan 19 '12 at 00:54