views:

39

answers:

3

Maybe this a newbie question, but according to my instruments there is a leak there, but im releasing the imageRef. i cant figure it out. its a category function.

-(UIImage *)imageAtRect:(CGRect)rect
{

CGImageRef imageRef = CGImageCreateWithImageInRect([self CGImage], rect);
UIImage* subImage = [UIImage imageWithCGImage: imageRef];
CGImageRelease(imageRef);
return subImage;

}
A: 
[self CGImage]

?

tadej5553
its a category function. so self is UIImage
Jinah Adam
A: 

It appears that you are leaking "subImage". imageWithCGImage: Creates and returns an image object representing the specified Quartz image. That means that the function creates a new image.

Make sure that you release the image later. That should get rid of the memory leak. Adding "autorelease" after "imageWithCGImage" will auto-magically get rid of the memory leak for you, depending on how you are using the returned value.

Steg132
imageWitCGImage returns an autoreleased reference.
fhj
so any other suggestions?
Jinah Adam