Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Foo new] vs [[Foo alloc] init]:



On 18 Feb 2008, at 13:11, Gregory Weston wrote:

You might think of +allocWithZone: as being the "designated allocator"
(pre-Leopard, at least) -- you would always override that rather than
+alloc.

You might think of it that way, but you'd have no formal reason to do so. The fact that alloc invokes allocWithZone: or that new invokes either of them is an implementation detail not exposed anywhere in the documentation or interface.

IMO it would be better if +alloc was explicitly documented to call +allocWithZone:, and if people were told to override the latter method in preference to the former (just filed as <rdar://5749202>). But I think a lot of us always assumed that things worked that way (and that we should override +allocWithZone:, not +alloc) because it's the same pattern as for -copy/-copyWithZone: and -mutableCopy/- mutableCopyWithZone:.


Relying on unpromised implementation details

I think the fact that this particular detail isn't documented is an oversight, rather than a conscious decision. I think that's what Bill has been trying to tell you. It probably *should* be documented, which is why I just filed a bug report.


Likewise, it seems that the fact that +new *wasn't* calling +alloc is arguably a bug (albeit a minor one), but since +allocWithZone:NULL should always have been equivalent to +alloc, overriding just +alloc would have been wrong in any case.

Kind regards,

Alastair.

--
http://alastairs-place.net


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Gregory Weston <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Bill Bumgarner <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Gregory Weston <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Bill Bumgarner <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Gregory Weston <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Bill Bumgarner <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Gregory Weston <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Bill Bumgarner <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Gregory Weston <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: "Hamish Allan" <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Gregory Weston <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.