objective-c – 使用ARC的神秘CoreImage内存泄漏
发布时间:2020-12-16 07:29:09 所属栏目:百科 来源:网络整理
导读:我遇到了一些使用“泄漏”仪器没有显示的大量内存泄漏.我弹出一个模态视图控制器并将2个Core Image过滤器应用于4或5个不同的图像.使用Instruments我可以看到内存在创建这些图像时跳起大约40-50 MB,但即使在我关闭模态视图控制器之后,我也从未获得该内存,并且
我遇到了一些使用“泄漏”仪器没有显示的大量内存泄漏.我弹出一个模态视图控制器并将2个Core
Image过滤器应用于4或5个不同的图像.使用Instruments我可以看到内存在创建这些图像时跳起大约40-50 MB,但即使在我关闭模态视图控制器之后,我也从未获得该内存,并且重复此过程后应用程序将崩溃2或3次.我很高兴你能提供任何建议,因为这让我非常疯狂.以下是有问题的方法:
UIView *finalView = [[UIView alloc] initWithFrame:CGRectMake(1024,1792,1345)]; UIImageView *templateImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,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)],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]; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 可以在线程之间共享相同的epoll文件描述符吗?
- C/C++`!a` vs`a == 0`
- Swift之Attempting to badge the application icon but hav
- XML的基本语法(XML实现html的网页布局的简单功能)
- Pods written in Swift can only be integrated as framewo
- ArcGIS Flex API for 3D—Papervision3D
- Windows下通过C#获取下指定进程监听的TCP/UDP端口号
- Swift 2.0初探:值得注意的新特性
- postgresql 优化
- 2009-03-16读书记录:《大话设计模式》第三章——单一职责原