我有两个函数,我应该使用哪一个?请解释它们的区别。
A:
A:
- (NSMutableArray *)FunctionA:(int)count {
NSMutableArray *a = [[NSMutableArray alloc] init];
for (int i = 0; i < count; i++) {
[a addObject:[NSNumber numberWithInt:0] ];
}
return [a autorelease];
}
B:
-(NSMutableArray *)FunctionB:(int)count {
NSMutableArray *b = [NSMutableArray arrayWithCapacity:count];
for (int i=0;i<count; i++){
[b addObject:[NSNumber numberWithInt:0] ];
}
return b; // or [b autorelease] ?
}