【发布时间】:2014-03-16 17:41:21
【问题描述】:
我有一个图像处理应用程序,用于测试 iOS 上块/线程的潜在加速。该算法运行良好,使用了大量内存,然后在运行后将其转储。
我制作了一个测试套件,该套件按顺序运行算法 10 次,并使用我的并行实现运行 10 次。如果我尝试在手机上运行它,它会因为内存压力而崩溃——它最终需要大约 432MB 的内存。然而,一旦套件完成,一切最终都会被清理干净:/
每次运行都使用大约 25MB 的内存。所以我认为解决方案是在每次运行后重置我的所有对象,它们会被清理干净。我基本上有 2 个处理对象来完成我的所有工作。因此,在每次运行后,我认为将它们设置为 nil 会导致它们被重新创建,旧版本被销毁并释放内存。但是,它对我的内存使用没有影响。
我还需要做些什么来释放通话之间的内存吗?我认为 Objective-C 现在正在使用引用计数,一旦我消除了唯一的引用——在我的 viewController 中——它就会被释放。任何建议将不胜感激。
这是我尝试释放内存的测试套件算法:
- (void)runTestSuite
{
// Sequential
NSLog(@"Sequential Run: ");
for (int i = 0; i < 10; i++) {
self.imageView.image = self.startImage;
self.imageManipulator = nil;
self.objectRecognizer = nil;
for (UIView *view in self.gameView.subviews) {
[view removeFromSuperview];
}
[self processImageInParallel:NO];
}
[self printResults];
[self clearResults];
// Parallel
NSLog(@"Parallel Run: ");
for (int i = 0; i < 10; i++) {
self.imageView.image = self.startImage;
self.imageManipulator = nil;
self.objectRecognizer = nil;
for (UIView *view in self.gameView.subviews) {
[view removeFromSuperview];
}
[self processImageInParallel:YES];
}
[self printResults];
[self clearResults];
}
【问题讨论】:
-
有相关代码可以分享吗?
-
@Merlevede 我不确定它是否有帮助,但我已经在 testSuite 中进行了编辑。我可以理解内存问题,因为
imageManipulator和objectRecognizer拥有完整的图像像素数据数组。我希望消除引用会清除它们 -
您可以将代码发布到
processImageInParallel:方法吗?每张图片有多大?
标签: ios iphone objective-c memory