• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [Foo new] vs [[Foo alloc] init]:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Subject: Re: [Foo new] vs [[Foo alloc] init]:
  • From: Jeff Johnson <email@hidden>
  • Date: Mon, 18 Feb 2008 07:46:00 -0600

On Feb 18, 2008, at 6:53 AM, Gregory Weston wrote:

On Feb 17, 2008, at 6:05 PM, Bill Bumgarner wrote:

If you are overriding +alloc for whatever reason, you better had override +allocWithZone:, too.

The real point is that there's no formal requirement that you do so. It only becomes an issue if you make unwarranted assumptions about the implementation.

If you're familiar with Cocoa, you know that the documentation is somewhat lacking. That sucks, but on this particular point the documentation seems reasonably clear. The Discussion for alloc begins as follows:


"The isa instance variable of the new instance is initialized to a data structure that describes the class; memory for all other instance variables is set to 0. The new instance is allocated from the default zone—use allocWithZone: to specify a particular zone."

Ok, it even mentions allocWithZone: right at the beginning, so let's read its Discussion:

"The isa instance variable of the new instance is initialized to a data structure that describes the class; memory for its other instance variables is set to 0. If zone is nil, the new instance will be allocated from the default zone (as returned by NSDefaultMallocZone)."

Now, it's not stated exactly and formally, but if you're familiar with Cocoa, you know that it's an extremely common pattern to have methods doSomething and doSomethingWithArgument:, where doSomething is implemented as doSomethingWithArgument:nil. Thus, if you're familiar with Cocoa, your first thought after reading those Discussions above is that maybe alloc is implemented as allocWithZone:nil.

And if you're not familiar with Cocoa, it's not the greatest idea to override such a crucial method as alloc.

-Jeff

_______________________________________________

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:
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: 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>)

  • Prev by Date: Re: [Foo new] vs [[Foo alloc] init]:
  • Next by Date: Image sources for the standard images such as NSImageNameQuickLookTemplate
  • Previous by thread: Re: [Foo new] vs [[Foo alloc] init]:
  • Next by thread: [Moderator] Re: [Foo new] vs [[Foo alloc] init]:
  • Index(es):
    • Date
    • Thread