Possible Duplicate:
alloc, init, and new in Objective-C
我对[Class new]
和[[Class alloc] init]
有点困惑.我已经使用[Class new]
和[[Class alloc] init]
定义了一个对象content
.
(1). NSMutableArray *content = [NSMutableArray new];
(2). NSMutableArray *content = [[NSMutableArray alloc] init];
我的问题是关于[Class new]
和[[Class alloc] init]
之间的区别.对我来说,(1)和(2)是相似的.如果(1)和(2)是相似的,那么为什么我们大部分时间使用[[Class alloc] init]
,而不是[Class new]
?我认为一定有一些不同.
请解释一下两者的区别、优缺点?