我找不到这个内存泄漏。我以为我一直在适本地发布东西。这是有问题的代码块。
- (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];
我正在创建局部变量,通过适当的 setter 将它们分配给我的实例变量,然后释放局部变量。我不确定发生了什么。
最佳答案
你有没有正确释放所有东西的dealloc
方法?
请注意,泄漏会向您显示某些内容的分配位置。它不会向您显示实际泄漏的位置;保留的内容没有明确平衡。
关于objective-c - 我找不到这个内存泄漏。我以为我正在正确地释放一切,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5012463/