我收到内存警告3次然后应用程序崩溃。
我有一个滑块需要将模糊值更改为UIImageView图像。 我尝试使用dispatch_async并使用imageView.image = nil清理图像内存;但问题没有解决。
来自uislider的代码调用:
dispatch_async(dispatch_get_main_queue(), ^(void)
{
imageView.image =nil;
imageView.image = [self blurImage:originalImage withValue:value];
});
-(UIImage *)blurImage:(UIImage *)theImage withValue:(nullable id)value
{
CIFilter *gaussianBlurFilter = [CIFilter filterWithName:@"CIGaussianBlur"];
[gaussianBlurFilter setDefaults];
CIImage *inputImage = [CIImage imageWithCGImage:[theImage CGImage]];
[gaussianBlurFilter setValue:inputImage forKey:kCIInputImageKey];
[gaussianBlurFilter setValue:value forKey:kCIInputRadiusKey];
CIImage *outputImage = [gaussianBlurFilter outputImage];
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef cgimg = [context createCGImage:outputImage fromRect:[inputImage extent]];
UIImage *image = [UIImage imageWithCGImage:cgimg];
return image;
}
答案 0 :(得分:1)
其中一个假设是你没有发布CIImageRef cgimg。这可能会增加内存。
-(UIImage *)blurImage:(UIImage *)theImage withValue:(nullable id)value
{
CIFilter *gaussianBlurFilter = [CIFilter filterWithName:@"CIGaussianBlur"];
[gaussianBlurFilter setDefaults];
CIImage *inputImage = [CIImage imageWithCGImage:[theImage CGImage]];
[gaussianBlurFilter setValue:inputImage forKey:kCIInputImageKey];
[gaussianBlurFilter setValue:value forKey:kCIInputRadiusKey];
CIImage *outputImage = [gaussianBlurFilter outputImage];
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef cgimg = [context createCGImage:outputImage fromRect:[inputImage extent]];
UIImage *image = [UIImage imageWithCGImage:cgimg];
//Release the core image reference
CGImageRelease(cgimg)
return image;
}