以下图形代码被iOS ARC标记为Leak [英] The following graphical code tagged as Leak by iOS ARC

查看:70
本文介绍了以下图形代码被iOS ARC标记为Leak的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 (UIImage *) cropToSquare:(UIImage *)_image 
 {
if(_image.size.height < _image.size.width)
{
    CGRect drawRect = CGRectMake(0, 0, _image.size.height, _image.size.height); 
    UIGraphicsBeginImageContext(drawRect.size);
    CGContextRef currentContext = UIGraphicsGetCurrentContext();
    CGRect cropArea = CGRectMake (((_image.size.width - _image.size.height)/2), 0, _image.size.height, _image.size.height);
    CGContextTranslateCTM(currentContext, 0.0, _image.size.height);
    CGContextScaleCTM(currentContext, 1.0, -1.0);
    CGContextDrawImage(currentContext, drawRect, CGImageCreateWithImageInRect (_image.CGImage, cropArea));
    UIImage *cropped = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return cropped;
}
else
{
    return _image;
}

}

行CGContextDrawImage(currentContext,drawRect,CGImageCreateWithImageInRect(_image.CGImage,cropArea))标记为100%泄漏。

The line CGContextDrawImage(currentContext, drawRect, CGImageCreateWithImageInRect (_image.CGImage, cropArea)) tagged 100% leakage.

我需要做与CG相关的任何事情吗?

Are there anything I need to do CG related release myself?

谢谢

推荐答案

我相信ARC仅适用于可可对象,

I believe that ARC only works for Cocoa objects, it doesn't work for Core* frameworks.

要修复泄漏,您需要更改为以下内容:

To fix your leak you need to change to the following:

CGImageRef myImage = CGImageCreateWithImageInRect (_image.CGImage, cropArea);
CGContextDrawImage(currentContext, drawRect, myImage);
CFImageRelease(myImage);

根据图像的大小,这可能是一个很大的泄漏。

That could be a pretty big leak, depending on the size of your images.

这篇关于以下图形代码被iOS ARC标记为Leak的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆