Question

When I analyze my iPhone app I have a blue arrow warning which says:

potential leak of an object stored into pauseImgBg

I simply crop a partial image from an atlas and put it into the pauseMenuIV imageView.

CGImageRef pauseImgBg = CGImageCreateWithImageInRect([UIImage imageNamed:@"atlas.png"].CGImage, CGRectMake(1, 1, 640.0f, 960.0f));
pauseMenu = [UIImage imageWithData:UIImagePNGRepresentation([UIImage imageWithCGImage:pauseImgBg])];// I have the blue arrow in this line
[pauseMenuIV setImage:pauseMenu];

What could be the problem ?
Thanks.

Was it helpful?

Solution

CGImageCreateWithImageInRect returns a CGImageRef with a retain count of +1. So you must release the recevied CGImageRef.

CGImageRelease(pauseImgBg);

in the end. Try and read the documentation when you have the time. It will help you to isolate these kinds of cases. From documentation

Core Foundation functions have names that indicate when you own a returned object:

  • Object-creation functions that have “Create” embedded in the name
  • Object-duplication functions that have “Copy” embedded in the name.

If you own an object, it is your responsibility to relinquish ownership when you have finished with it.

And from the documentation of CGImageCreateWithImageInRect itself

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

OTHER TIPS

you'll probably need to release it via

CGImageRelease(pauseImgBg);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top