I\'m having a memory leak when using this custom method which returns a CGImageRef. I can\'t release \"cgImage\" properly because I have to return it. What chould I do ?
cgImage
is owned by your method, you need to return it and give responsibility to the caller to release it through CFRelease
.
You can also return the CGImage
wrapped inside a UIImage
instance, like this:
UIImage *image = [UIImage imageWithCGImage:cgImage];
CFRelease(cgImage); //cgImage is retained by the UIImage above
return image;