On Aug 16, 2016, at 02:20 , Alex Zavatone <z...@mac.com> wrote:
> 
> Is there any risk to using [NSArray new] to init an array instead of [NSArray 
> array]??

The only real difference between the two is the ownership semantics of the 
returned object. For ‘new’ it’s +1 and for ‘array’ it’s +0. However, in an ARC 
environment, ARC takes care of the ownership for you, so you can use them 
interchangeably.

You might care about the difference if, say, you’re creating 10’s of thousands 
of arrays, because the +0 ownership may be implemented by autoreleasing the 
object, which adds work in draining the autorelease pool later. However, ARC 
can sometimes avoid even the autorelease, so worrying about this in advance is 
pointless.

AFAICT, the main reason *not* to use ‘new’ is to avoid generating anxiety for 
those who come back to read the code later, and who might worry that the 
inconsistency means something.

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to