【问题标题】:iOS - CGImageRef Potential LeakiOS - CGImageRef 潜在泄漏
【发布时间】:2015-07-25 11:59:36
【问题描述】:

我有这个代码:

CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], rect);
UIImage *outputimage = [UIImage imageWithCGImage:imageRef
                                           scale:image.scale
                                     orientation:UIImageOrientationUp];

我收到警告:

对象泄露:分配并存储到“imageRef”中的对象不是 稍后在此执行路径中引用,并且保留计数为 +1

但我使用的是 ARC,无法使用 releaseautoRelease。如何解决?

【问题讨论】:

    标签: ios memory-leaks cgimageref


    【解决方案1】:

    只需添加此代码

    CGImageRelease(imageRef);
    

    来自CGImageCreateWithImageInRect 文档,

    生成的图片保留了对原图的引用,也就是说你可以在调用这个函数后释放原图。

    所以,您只需调用CGImageRelease 使其保留计数-1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-07
      相关资源
      最近更新 更多