• 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: Bill Bumgarner <email@hidden>
  • Date: Sun, 17 Feb 2008 08:13:08 -0800

On Feb 17, 2008, at 5:25 AM, Gregory Weston wrote:
You've repeated the assertion without actually explaining it. How would it be a binary compatibility issue for new to either start or stop directly invoking alloc or allocWithZone: rather than simply performing comparable operations? If I can override +alloc to do whatever I like as long as it performs a certain minimum required set of actions, why would be be troublesome for +new to not directly invoke +alloc as long as it performed that minimum required set of actions?

(1) Developer declares a subclass of NSObject that overrides, say, +alloc


(2) Developer instantiates said class through +new

(3) Apple changes the implementation of +new in, say, 10.9 to no longer call +alloc

(4) Developer's application that had been compiled on, say, 10.4 and has run without recompilation on 10.4, 10.5, 10.6, 10.7 and 10.8 now breaks when double-clicked on 10.9

When Apple released Leopard, there was a general expectation -- a general requirement -- that any application compiled/built on prior releases of Mac OS X would work on Leopard.

Any application that does not, as per the above hypothetical example, continue to work across a major OS release boundary or a software update is considered to be a binary compatibility issue.


... is false. It wasn't correct by default before 10.5 and it's not reliable in any version of OS X. You can make it true by adding additional conditions, and you can question the sanity of the individual developer who makes it untrue for any of their classes (in which case I'd likely join you), but the proposition is not true as presented. Assuming it *is* true - that somehow new by definition must invoke alloc - is an error and relying on that assumption can get you into trouble. For example, if you support deployment on Tiger, override +alloc in one of your classes and use +new to instantiate that class, your override will not be used. That's all I've been trying to say.

I'm not sure where your claim that +new was not implemented by calling +alloc/+allocWithZone: followed by -init. I looked at the source back to 10.1. +new was implemented as a call to +alloc or +allocWithZone: followed by a call to -init since at least 10.1.


The documentation is quite clear -- +new is a combination of +alloc and -init. How that contract could be met without actually calling said methods is unclear to me.

b.bum

_______________________________________________

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

  • Prev by Date: Re: Help with displaying encrypted PDF image
  • Next by Date: Xcode 3.0 Hangs on Build or Save
  • Previous by thread: Re: [Foo new] vs [[Foo alloc] init]:
  • Next by thread: Re: [Foo new] vs [[Foo alloc] init]:
  • Index(es):
    • Date
    • Thread