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

标签 objective-c memory ios5 memory-leaks

我遇到了一些使用“泄漏”工具没有显示出来的大量内存泄漏。我弹出一个模态视图 Controller 并将 2 个 CoreImage 过滤器应用于 4 或 5 个不同的图像。使用 Instruments 我可以看到在创建这些图像时内存跳跃了大约 40-50 MB,但即使在我关闭模态视图 Controller 之后,我也永远无法恢复内存,并且应用程序将在重复此过程 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%(115 MB 对比 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];

关于objective-c - 使用 ARC 的神秘 CoreImage 内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9388742/

相关文章:

c++ - 多对象手写单链表段错误

ios - 数组中最后添加的对象

objective-c - 在结构中传递指向指针的指针时出现 EXC_BAD_ACCESS?

ios - 将 iCloud 商店迁移到本地商店并确保数据在每次应用程序启动时都在那里

python - 诊断 boto3 中的内存泄漏

Ruby/Mechanize 有什么方法可以耗尽 RAM? -> 分配内存失败

ios - 还有其他人遇到 iOS 5 加密问题吗?

iphone - 我们可以在应用程序中使用苹果相册图像吗?

iphone - 是否有API调用可为您提供iPhone用户的“我的信息”联系人数据库记录?

objective-c - 将多个详细 View 与 Split View Controller 一起使用