【发布时间】:2012-05-22 10:18:14
【问题描述】:
我正在 ViewVillAppear 中加载我的 plist 文件,如下所示。在第一次加载时我没有泄漏但是按下其他 tabBar 按钮/项目并返回到这个视图我得到了泄漏。我已经在 dealloc 中发布了这个 NSMutableArray 但是它仍然泄漏。有点困惑为什么。 (theProducts3 是一个 NSMutableArray,就像 .h 中的 ivar 一样,它不是 @property 或保留的)
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *plistPath = [rootPath stringByAppendingPathComponent:@"basket.plist"];
theProducts3 = [[NSMutableArray alloc] initWithContentsOfFile:plistPath];
NSLog(@"Number of objects in item array %i", [theProducts3 count]);
}
在这里释放 NSMutable 数组。
-(void)dealloc{
[theProducts3 release];
[super dealloc];
}
任何指针最感激!谢谢...
【问题讨论】:
-
不,不要自动释放它,这会导致间歇性崩溃。由于没有其他东西保留该数组,它将被释放,您将留下一个悬空指针。
标签: ios memory-leaks nsmutablearray plist initwithcontentsoffile