【发布时间】:2014-06-15 07:29:10
【问题描述】:
我们使用下面的代码在图像视图中设置图像,
@autoreleasepool {
UIImageView *titleView = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"ImgTitle" ofType:@"png"]]];
}
Instruments 在上面两行显示内存泄漏。我们检查了 Xcode 5.0.1 到 iOS7。
请任何人建议解决该问题。
【问题讨论】:
-
我能知道将代码写入@autoreleasepool 的原因吗??
-
我们使用了 UIImageView *titleView = [[UIImageView alloc]initWithImage: [UIImage imageWithContentsOfFile: [[NSBundle mainBundle]pathForResource: @"ImgTitle" ofType:@"png"]]];单独的代码。为了减少内存泄漏,我们将代码放在自动释放池中,现在内存泄漏百分比会降低,但仍然会发生泄漏。
-
你用过这个吗,[游泳池排水管];
-
@Ramdy 和 \@autoreleasepool,他不需要排空池。
-
在 ARC 下,此代码不应泄漏任何内存,请粘贴您的仪器快照。
标签: ios memory-leaks uiimage automatic-ref-counting instruments