【发布时间】:2011-06-28 02:26:09
【问题描述】:
我找不到这个内存泄漏。我以为我一直在适当地释放东西。这是有问题的代码块。
- (void) createProvince:(NSString *) provinceName {
// if province does not exist create it
if ([self hasProvince: provinceName] == NO) {
// get the province object
NSPredicate *predicate;
predicate = [NSPredicate predicateWithFormat:@"Name == %@", provinceName];
NSMutableArray *provArray = [[NSMutableArray alloc] init];
[provArray setArray: [CoreDataHelper searchObjectsInContext:@"Province" :predicate :@"Name" :YES :[self managedObjectContext]]];
NSIndexPath *indexPath;
indexPath = [NSIndexPath indexPathForRow:0 inSection: 0];
[[self provinces] addObject: [provArray objectAtIndex: [indexPath row]]];
[provArray release];
// create a cities array to hold its selected cities
NSMutableArray *array = [[NSMutableArray alloc] init];
[[self cities] addObject: array];
[array release];
}
}
漏洞在这里:
[[self provinces] addObject: [provArray objectAtIndex: [indexPath row]]];
NSMutableArray *array = [[NSMutableArray alloc] init];
[[self cities] addObject: array];
我正在创建局部变量,通过适当的设置器将它们分配给我的实例变量,然后释放局部变量。我不确定发生了什么。
【问题讨论】:
标签: objective-c debugging ios memory-leaks