Skip navigation.
 
mlRe: [Foo new] vs [[Foo alloc] init]:
FROM : Bill Bumgarner
DATE : Sat Feb 16 18:11:27 2008

On Feb 16, 2008, at 4:56 AM, Gregory Weston wrote:
> Without that guarantee, there's a different between saying "this 
> statement accurately describes all current implementations" and 
> "this statement is correct." It is not correct in general to say 
> that "[Foo new] is exactly equivalent to [[Foo alloc] init]." Those 
> are the kind of assumptions that burn you after you've forgotten you 
> made them in the first place.


In general, I agree.  In this particular case, I'm not concerned.  If 
Apple were to change the implementation of +new to *not* do +alloc 
followed by -init, many many bits of code would break.  Binary 
compatibility between release of Mac OS X is critical and, thus, this 
particular behavior cannot change.

Reading the docs, it explicitly states:

...
This method is a combination of alloc and init. Like alloc, it 
initializes the isa instance variable of the new object so it points 
to the class data structure. It then invokes the init method to 
complete the initialization process.
...

From there, the documentation entirely discusses implementing +new... 
as a cover for various -initWith... style initializers.

Thus, the bare behavior of +new is quite thoroughly well defined as a 
combination of +alloc and -init (in the docs, the the two method names 
are links to the documentation of said methods).

b.bum

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