【问题标题】:Climbing CFData memory usage when using Core Image filters使用 Core Image 过滤器时攀爬 CFData 内存使用情况
【发布时间】:2012-11-18 18:05:15
【问题描述】:

我遇到了分配内存过多的问题。我的应用程序分配内存达到 100MB! 是的......我正在使用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;
}

内存警告后内存使用量并没有下降,所以应该不是缓存问题。

【问题讨论】:

  • 你如何存储返回的图像?
  • 或者,换句话说,调用代码是什么样的?问题中的代码示例看起来不错。另外,泄漏仪器怎么说?
  • 你运行静态分析器了吗?产品 > 分析。它会给你任何诊断吗?
  • 静态分析仪什么也没给我。并且泄漏仪器没有显示任何泄漏。 pastebin.com/wDJhzu4G我调用 ReDraw 方法来重绘存储在列表中的所有过滤器。
  • 据我所知 CGImageRelease(cgimg);第一次应用过滤器后不起作用,因为它不会释放由 cgimg = [context createCGImage:outputImage fromRect:[outputImage extent]] 创建的图像;

标签: iphone automatic-ref-counting dealloc core-image cfdata


【解决方案1】:

我在一个示例项目(使用 ARC)上运行了您的代码,它没有任何泄漏或额外分配。 CFData 本质上与CIFilter 子类无关,而是与CIImage 相关。问题出在其他地方。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-19
    • 1970-01-01
    • 2012-05-27
    • 2018-03-26
    • 1970-01-01
    • 2011-12-23
    • 2015-03-25
    • 1970-01-01
    相关资源
    最近更新 更多