【发布时间】:2013-09-26 13:46:33
【问题描述】:
我有以下代码:
NSString *bgImageName = [[Useful instance] getRootviewBackgroundImageName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:bgImageName]];
imageView.clipsToBounds = YES;
CGRect rc = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[imageView setFrame:rc];
[self.view insertSubview:imageView atIndex:0];
[imageView release];
Instruments 在上述代码的第二行显示 100% 和内存泄漏,而在 xcode 4.6 中并非如此。我现在在 osx 10.8.5 上使用 xCode 5
看来,我正确释放了分配的 UIImageView(第 7 行),它在第 6 行插入到我的视图中,所以我看不出为什么仪器会发出内存泄漏警告。
有人知道为什么仪器会显示(在我看来)错误信息吗?
编辑:这是带有我的泄漏对象的分配摘要的仪器屏幕截图:
UIKit 和 QuartzCore 保留了我的对象,这就是我泄漏 UIImageView 的原因(或者我对这个假设有误?)。
UIImageView 被插入到我的 xib 文件中引用的视图(UIViewController)中。将我添加的UIImageView 添加到“self.view”后如何控制它会发生什么?
【问题讨论】:
-
什么对象被泄露了?
-
“UIImageView”对象
-
我有类似的东西,我看到它只发生在模拟器 [imageview setImage:[UIImage imageNamed:@"img-568h@2x"]]; (在这里泄漏)我正在使用 arc xcode 5 ios 7
-
@dave 只有在针对 iOS 7 使用模拟器进行分析时才会出现泄漏。使用设备或模拟器针对所有 iOS 版本进行分析永远不会出现任何内存泄漏警告(请参阅 Dan Marinescu 的回答)
标签: ios objective-c xcode instruments