Memory leaks UIGraphicsBeginImageContext创建的图像永远保留在内存中

Memory leaks UIGraphicsBeginImageContext创建的图像永远保留在内存中,memory-leaks,uiimage,core-graphics,cgcontext,cgimage,Memory Leaks,Uiimage,Core Graphics,Cgcontext,Cgimage,我正在使用核心图形创建图像的许多颜色变化。我总共需要创建大约320个,但逐渐地,应用程序的内存使用量不断增加,直到崩溃。从仪器中,我看到更多的CGImage对象被创建并保持活力。我想释放它们,因为我以PNG格式将图像存储到缓存目录中 我已经搜索了所有其他我能找到的解决方案,但没有成功。感谢您的帮助。谢谢 以下是主要部分: +(UIImage*)色调图像来自图像:(UIImage*)源图像颜色:(UIColor*)颜色强度:(float)强度{ if(UIGraphicsBeginImageCon

我正在使用核心图形创建图像的许多颜色变化。我总共需要创建大约320个,但逐渐地,应用程序的内存使用量不断增加,直到崩溃。从仪器中,我看到更多的CGImage对象被创建并保持活力。我想释放它们,因为我以PNG格式将图像存储到缓存目录中

我已经搜索了所有其他我能找到的解决方案,但没有成功。感谢您的帮助。谢谢

以下是主要部分:

+(UIImage*)色调图像来自图像:(UIImage*)源图像颜色:(UIColor*)颜色强度:(float)强度{
if(UIGraphicsBeginImageContextWithOptions!=NULL){
UIGraphicsBeginImageContextWithOptions(sourceImage.size,NO,0.0);
}否则{
UIGraphicsBeginImageContext(sourceImage.size);
}
CGContextRef context=UIGraphicsGetCurrentContext();
CGRect rect=CGRectMake(0,0,sourceImage.size.width,sourceImage.size.height);
//绘制阿尔法蒙版
CGContextSetBlendMode(上下文,kCGBlendModeNormal);
CGContextDrawImage(context、rect、sourceImage.CGImage);
//绘制着色颜色,保留原始图像的alpha值
CGContextSetBlendMode(上下文,kCGBlendModeSourceIn);
[颜色设置填充];
CGContextFillRect(上下文,rect);
//将原始灰度模板设置为新图像的覆盖
sourceImage=[self-verticallyFlipImage:sourceImage];
[sourceImage drawInRect:CGRectMake(0,0,sourceImage.size.width,sourceImage.size.height)blendMode:kCGBlendModeMultiply alpha:intensity];
UIImage*ColoureImage=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsSendImageContext();
COLOREDIMAGE=[自垂直LIPIMAGE:COLOREDIMAGE];
返回彩色图像;
}
这用于翻转图像:

+(UIImage*)垂直LipImage:(UIImage*)原始图像{
UIImageView*tempImageView=[[UIImageView alloc]initWithImage:originalImage];
UIGraphicsBeginImageContext(tempImageView.frame.size);
CGContextRef context=UIGraphicsGetCurrentContext();
CGAffineTransform flipVertical=CGAffineTransformMake(1,0,0,-1,0,tempImageView.frame.size.height);
CGContextConcatCTM(上下文,flipVertical);
[tempImageView.layer renderInContext:context];
UIImage*flippedImage=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsSendImageContext();
返回翻转图像;
}

添加到
verticallyFlipImage
tempImageView.image=nil以使图像视图释放图像。这就解决了问题