CGImageRef Memory leak

前端 未结 4 1035
一个人的身影
一个人的身影 2020-12-10 06:35

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 ?

4条回答
  •  抹茶落季
    2020-12-10 07:19

    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;
    

提交回复
热议问题