• 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: Gregory Weston <email@hidden>
  • Date: Sat, 16 Feb 2008 07:56:41 -0500


On Feb 15, 2008, at 6:11 PM, Bill Bumgarner wrote:

On Feb 15, 2008, at 1:55 PM, Gregory Weston wrote:
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.

Possible? Sure. But one would be mighty optimistic to make such a subtle distinction.

Mighty optimistic? I'd think "appropriately pessimistic" would be a better description.


On Leopard, +new is implemented as return [[self alloc] init]; It is equivalent unless a subclass overrides, which is exceedingly unlikely.

Where's the documentation that says that's reliable?

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.
_______________________________________________


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


  • Follow-Ups:
    • Re: [Foo new] vs [[Foo alloc] init]:
      • From: Bill Bumgarner <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>)

  • Prev by Date: determining free memory
  • Next by Date: Re: acceptable method for finding path to /usr/bin
  • Previous by thread: Re: [Foo new] vs [[Foo alloc] init]:
  • Next by thread: Re: [Foo new] vs [[Foo alloc] init]:
  • Index(es):
    • Date
    • Thread