Objective c 使用ARC的神秘CoreImage内存泄漏

Objective c 使用ARC的神秘CoreImage内存泄漏,objective-c,memory,ios5,memory-leaks,Objective C,Memory,Ios5,Memory Leaks,我遇到了一些使用“泄漏”工具无法显示的大规模内存泄漏。我弹出一个模态视图控制器,对4或5个不同的图像应用2个CoreImage过滤器。使用仪器,我可以看到在创建这些图像时,内存会增加约40-50MB,但即使在我关闭了Modal View控制器之后,我也无法恢复内存,并且在重复此过程2到3次后,应用程序将崩溃。我很高兴你能提供任何建议,因为这让我简直疯了。以下是所讨论的方法: UIView *finalView = [[UIView alloc] initWithFrame:CGRectMake(

我遇到了一些使用“泄漏”工具无法显示的大规模内存泄漏。我弹出一个模态视图控制器,对4或5个不同的图像应用2个CoreImage过滤器。使用仪器,我可以看到在创建这些图像时,内存会增加约40-50MB,但即使在我关闭了Modal View控制器之后,我也无法恢复内存,并且在重复此过程2到3次后,应用程序将崩溃。我很高兴你能提供任何建议,因为这让我简直疯了。以下是所讨论的方法:

UIView *finalView = [[UIView alloc] initWithFrame:CGRectMake(1024, 0, 1792, 1345)];
UIImageView *templateImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1792, 1345)];
templateImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@.png",[theme objectForKey:@"template_background"]]];

//CI background Setup
NSString *filePath5 = [[NSBundle mainBundle] pathForResource:[theme objectForKey:@"template_background"] ofType:@"png"];
NSURL *fileNameAndPath5 = [NSURL fileURLWithPath:filePath5];

    @autoreleasepool {

        finalBackBeginImage = [CIImage imageWithContentsOfURL:fileNameAndPath5];
        finalBackImage = [CIFilter filterWithName:@"CIHueAdjust" keysAndValues:@"inputAngle", [NSNumber numberWithFloat:[[boothPrefs objectForKey:@"templateBackground_hue"] floatValue]*6.28], @"inputImage", finalBackBeginImage, nil].outputImage;
        finalBackImage = [CIFilter filterWithName:@"CIColorControls" keysAndValues:@"inputSaturation", [NSNumber numberWithFloat:([[boothPrefs objectForKey:@"templateBackground_saturation"] floatValue] * 5)], @"inputImage", finalBackImage, nil].outputImage;

        finalBackContent = [CIContext contextWithOptions:nil];
        CGImageRef cgimgFinalBack = 
        [finalBackContent createCGImage:finalBackImage fromRect:[finalBackImage extent]];
        UIImage *newFinalBackImg = [UIImage imageWithCGImage:cgimgFinalBack];
        [templateImageView setImage:newFinalBackImg];
        CGImageRelease(cgimgFinalBack);

    }

[finalView addSubview:templateImageView];

我已使用下面的代码从使用imageNamed切换到使用imageWithData。在5分钟的测试中(很抱歉,我现在花了将近12个小时在这个问题上),我发现我对同一操作的实际内存使用量降低了50%(115mb对230MB),神秘的“Push+80mb,pop-30mb”实际内存问题似乎得到了解决。

不过我还是祈求好运

//use images like this as base images for CIFilters
    NSData* imageData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:self.frameName ofType:nil]];
        ;
        UIImage* imageForFilter =[UIImage imageWithData: imageData];

作为参考,一些被修改的图像是1024 x 768 PNG,还有一些更大,可能是1700 x 1300。我理解为什么需要大量内存来处理这些过滤器,我只是不理解为什么不发布。下次调用此函数之前是否删除templateImageView不,添加到finalView的每个图像都有自己的UIImageView。templateImageView只是其中的第一个。你不是唯一一个被这个问题逼疯的人!这真的很糟糕,我把范围缩小到使用CIFilters
ImageName:
缓存生成的图像,因此它主要用于多次使用的图像(例如工具栏图标等)。这只为我们节省了70兆。谢谢