Skip navigation.
 
mlRe: [Foo new] vs [[Foo alloc] init]:
FROM : Gregory Weston
DATE : Fri Feb 15 22:55:18 2008

Keith Duncan wrote:

>> As far as I understand, [Foo new] is exactly equivalent to [[Foo
>> alloc] init]

>
> Correct.


Incorrect. Based on the documentation new (by default) does setup 
work analogous to alloc and then invokes init before returning the 
object. It does not actually use the alloc method, though, which 
means it's entirely possible for new to not be equivalent to an alloc/
init pair.

> Chaining alloc and init is just the in vogue convention as far as I
> know. I've been told that -new used to be a popular way of doing it
> back in the days of NeXTStep.


It's more than just the 'in vogue convention' though. The point was 
to recognize that allocation and initialization are distinct actions 
and there's benefit in having them be separable. With alloc/init you 
can change one of the phases without concern for the other.

Related mailsAuthorDate
mlRe: [Foo new] vs [[Foo alloc] init]: Gregory Weston Feb 15, 22:55
mlRe: [Foo new] vs [[Foo alloc] init]: Adam P Jenkins Feb 16, 00:05
mlRe: [Foo new] vs [[Foo alloc] init]: Bill Bumgarner Feb 16, 00:11
mlRe: [Foo new] vs [[Foo alloc] init]: Hamish Allan Feb 16, 00:26
mlRe: [Foo new] vs [[Foo alloc] init]: Bill Bumgarner Feb 16, 00:39
mlRe: [Foo new] vs [[Foo alloc] init]: Gregory Weston Feb 16, 13:56
mlRe: [Foo new] vs [[Foo alloc] init]: Bill Bumgarner Feb 16, 18:11
mlRe: [Foo new] vs [[Foo alloc] init]: Gregory Weston Feb 16, 22:16
mlRe: [Foo new] vs [[Foo alloc] init]: Bill Bumgarner Feb 17, 00:28
mlRe: [Foo new] vs [[Foo alloc] init]: Gregory Weston Feb 17, 14:25
mlRe: [Foo new] vs [[Foo alloc] init]: Bill Bumgarner Feb 17, 17:13
mlRe: [Foo new] vs [[Foo alloc] init]: Gregory Weston Feb 17, 20:15
mlRe: [Foo new] vs [[Foo alloc] init]: Bill Bumgarner Feb 17, 21:06
mlRe: [Foo new] vs [[Foo alloc] init]: Gregory Weston Feb 17, 23:28
mlRe: [Foo new] vs [[Foo alloc] init]: Bill Bumgarner Feb 18, 00:05
mlRe: [Foo new] vs [[Foo alloc] init]: Hamish Allan Feb 18, 00:47
mlRe: [Foo new] vs [[Foo alloc] init]: j o a r Feb 18, 01:47
mlRe: [Foo new] vs [[Foo alloc] init]: Gregory Weston Feb 18, 13:53
mlRe: [Foo new] vs [[Foo alloc] init]: Gregory Weston Feb 18, 14:11
mlRe: [Foo new] vs [[Foo alloc] init]: Jeff Johnson Feb 18, 14:46
mlRe: [Foo new] vs [[Foo alloc] init]: Alastair Houghton Feb 18, 14:58
ml[Moderator] Re: [Foo new] vs [[Foo alloc] init]: Scott Anguish Feb 18, 20:33