Iphone 使用核心图像过滤器时的数据内存使用率
我的内存分配太多了。我的应用程序alloc mem高达100MB! 是的。。。我正在使用Iphone 使用核心图像过滤器时的数据内存使用率,iphone,automatic-ref-counting,dealloc,core-image,cfdata,Iphone,Automatic Ref Counting,Dealloc,Core Image,Cfdata,我的内存分配太多了。我的应用程序alloc mem高达100MB! 是的。。。我正在使用ARC。大部分内存是通过CFData分配的(据我所知,它是CoreImage过滤器)。对图像应用过滤器后,CFData分配的内存增加约1.3mb,并且不会取消分配: 代码如下所示: +(UIImage*)BWFilter:(UIImage *)imgFX { CIImage *sourceImage = [[CIImage alloc] initWithImage:imgFX]; CIIm
ARC
。大部分内存是通过CFData
分配的(据我所知,它是CoreImage
过滤器)。对图像应用过滤器后,CFData
分配的内存增加约1.3mb,并且不会取消分配:
代码如下所示:
+(UIImage*)BWFilter:(UIImage *)imgFX
{
CIImage *sourceImage = [[CIImage alloc] initWithImage:imgFX];
CIImage *blackAndWhite = [CIFilter filterWithName:@"CIColorControls" keysAndValues:kCIInputImageKey, sourceImage, @"inputBrightness", [NSNumber numberWithFloat:0.0], @"inputContrast", [NSNumber numberWithFloat:1.1], @"inputSaturation", [NSNumber numberWithFloat:0.0], nil].outputImage;
CIImage *output = [CIFilter filterWithName:@"CIExposureAdjust" keysAndValues:kCIInputImageKey, blackAndWhite, @"inputEV", [NSNumber numberWithFloat:0.7], nil].outputImage;
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef cgiimage = [context createCGImage:output fromRect:output.extent];
imgFX = [UIImage imageWithCGImage:cgiimage];
if (cgiimage) {
CGImageRelease(cgiimage);
}
return imgFX;
}
内存警告后,内存使用率不会下降,因此不应该是缓存问题。我在一个示例项目(使用ARC)上运行了您的代码,它不会提供任何泄漏或额外分配
CFData
基本上与CIFilter
子类无关,而是与CIImage
相关。问题出在其他地方。如何存储返回的图像?或者,换句话说,调用代码是什么样子的?问题中的代码示例看起来不错。还有,泄漏仪器怎么说?你运行静态分析仪了吗?产品>分析。它能给你们诊断吗?静态分析仪什么都不给。和泄漏仪器没有显示任何泄漏。我调用ReDraw方法来重画列表中存储的所有过滤器;第一次应用筛选器后不工作,因为它不会释放由cgimg=[context createCGImage:outputImage fromRect:[outputImage extent]]创建的图像;