• 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: array = [NSArray new] or array = [NSArray array]?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: array = [NSArray new] or array = [NSArray array]?


  • Subject: Re: array = [NSArray new] or array = [NSArray array]?
  • From: Quincey Morris <email@hidden>
  • Date: Fri, 19 Aug 2016 10:50:42 -0700
  • Feedback-id: 167118m:167118agrif8a:167118sPviqTo1R6:SMTPCORP

On Aug 16, 2016, at 02:20 , Alex Zavatone <email@hidden> 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 (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: array = [NSArray new] or array = [NSArray array]?
      • From: email@hidden
References: 
 >array = [NSArray new] or array = [NSArray array]? (From: Alex Zavatone <email@hidden>)

  • Prev by Date: Re: Resend: array = [NSArray new] or array = [NSArray array]?
  • Next by Date: Re: Resend: array = [NSArray new] or array = [NSArray array]?
  • Previous by thread: Re: array = [NSArray new] or array = [NSArray array]?
  • Next by thread: Re: array = [NSArray new] or array = [NSArray array]?
  • Index(es):
    • Date
    • Thread