Cocoa's memory management naming policy states that you own an object created from methods that start with alloc, copy, or new.
These rules are also respected by the Clan Static Analyzer.
Note that there are slightly different conventions for the Core Foundation. See the Apple Extended Memory Management Programming Guide for more details.
I modified your above method to fit these naming conventions. I also removed the asterisk when passing in anImage , since CGImageRef already a pointer. (Or was it on purpose?).
Note that you have returned CGImage and it should CGImageRelease later.
-(CGImageRef)newResizedImageWithImage:(CGImageRef)anImage width:(CGFloat)width height:(CGFloat)height { CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(anImage); if (alphaInfo == kCGImageAlphaNone) { alphaInfo = kCGImageAlphaNoneSkipLast; } CGContextRef bitmap = CGBitmapContextCreate(NULL, width, height, CGImageGetBitsPerComponent(anImage), 4 * width, CGImageGetColorSpace(anImage), alphaInfo); CGContextDrawImage(bitmap, CGRectMake(0, 0, width, height), anImage); CGImageRef image = CGBitmapContextCreateImage(bitmap); CGContextRelease(bitmap); return image; }
source share