gpt4 book ai didi

ios - 以下图形代码被 iOS ARC 标记为 Leak

转载 作者:行者123 更新时间:2023-11-28 20:31:56 25 4
gpt4 key购买 nike

 (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% 泄漏。

我需要自己做 CG 相关的发布吗?

谢谢

最佳答案

我认为 ARC 仅适用于 Cocoa 对象,不适用于 Core* 框架。

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

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

这可能是一个相当大的泄漏,具体取决于图像的大小。

关于ios - 以下图形代码被 iOS ARC 标记为 Leak,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11853845/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com