objective-c – 使用ARC的神秘CoreImage内存泄漏

我遇到了一些使用“泄漏”仪器没有显示的大量内存泄漏.我弹出一个模态视图控制器并将2个Core
Image过滤器应用于4或5个不同的图像.使用Instruments我可以看到内存在创建这些图像时跳起大约40-50 MB,但即使在我关闭模态视图控制器之后,我也从未获得该内存,并且重复此过程后应用程序将崩溃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对比高达230 mb)和神秘的“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];
点赞