下面的 self.listOfCustDetail 和 self.listOfCustomer 中存在内存泄漏
-(void) calCustList {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *plistPath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"customer.plist"];
self.listOfCustDetail = [[[NSMutableArray alloc] init] autorelease];
self.listOfCustomer = [[[NSMutableArray alloc] init] autorelease];
self.customers = [[[NSMutableDictionary alloc] initWithContentsOfFile:plistPath] autorelease];
[self.listOfCustomer removeAllObjects];
[self.listOfCustDetail removeAllObjects];
[self.listOfCustomer addObject:@"新紀錄"];
[self.listOfCustDetail addObject:@""];
for (id key in self.customers) {
NSString *s = [NSString stringWithFormat:@"%@,%@,%@,%@", [[self.customers objectForKey:key] objectAtIndex:0], [[self.customers objectForKey:key] objectAtIndex:1], [[self.customers objectForKey:key] objectAtIndex:2], [[self.customers objectForKey:key] objectAtIndex:3]];
[self.listOfCustomer addObject:key];
[self.listOfCustDetail addObject:s];
}
}
如何定义您的属性? 他们保留吗?如果它们确实保留了,那么您正在显示的代码段中没有实际错误。
该方法多久调用一次?如果经常调用它,您可以使用自定义NSAutoreleasePool
。
此外,新初始化的阵列上也不需要以下两行:
[self.listOfCustomer removeAllObjects];
[self.listOfCustDetail removeAllObjects];
您是否显示实际源代码?
我想
建议,在项目中启用ARC(自动引用计数),因为您不需要释放数组