3

Out of some 2k lines of code, the Static Analyser has only one problem, thus:

spellDetailModalViewController  *detailVC = [[spellDetailModalViewController alloc]init];
UIImage *tempImage = self.spellImageView.image;
CGRect newSize = CGRectMake(0.0, 0.0, 320.0, 305.0);
CGImageRef temp = CGImageCreateWithImageInRect([tempImage CGImage], newSize);
UIImage *passingImage = [UIImage imageWithCGImage:temp];
temp=nil;

It is complaining that CGImageRef 'temp' is 'potentially' being leaked, and has a retain count of +1. I set it to nil after the image has been passed to the modal ViewController. Obviously, under ARC, I can't call [temp release] under ARC. Not sure what to do. Help greatly appreciated.

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Skybird
  • 159
  • 1
  • 11

2 Answers2

4

You need to CGImageRelease temp

CGImageRef temp = CGImageCreateWithImageInRect([tempImage CGImage], newSize);
UIImage *passingImage = [UIImage imageWithCGImage:temp];
CGImageRelease(temp);

From the CGImageCreateWithImageInRect Apple docs:

The resulting image retains a reference to the original image, which means you may release the original image after calling this function.

justin
  • 104,054
  • 14
  • 179
  • 226
zaph
  • 111,848
  • 21
  • 189
  • 228
  • Many thanks @CocoaFu - that has solved it immediately. I couldn't find that in the docs, hence my question. I really appreciate your help - cheers. – Skybird Jan 08 '12 at 20:47
  • @CocoaFu you're welcome =) i can't remember with certainty if the change i made actually makes any difference (beyond the ability to pass `NULL` without an error). – justin Jan 08 '12 at 23:22
0

CGImage is a Core Graphics object and ARC can not handle Core Libraries. So you should use CGImageRelease or better way to pass that warning, use imageWithCIImage method like that;

CIImage *fooImage = [CIImage imageWithCGImage:temp.CGImage];
UIImage *passingImage = [UIImage imageWithCIImage:fooImage];
Kemal Can Kaynak
  • 1,638
  • 14
  • 26