• 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: Arc and autorelease
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Arc and autorelease


  • Subject: Re: Arc and autorelease
  • From: Ken Thomases <email@hidden>
  • Date: Thu, 24 May 2012 10:26:59 -0500

On May 24, 2012, at 3:14 AM, Gerriet M. Denkmann wrote:

> Without Arc, this:
>
> NSString *s = [ [ NSString alloc ] initWithFormat: ...];
> [ someCollection addObject: s ];
> [ s release ];
>
> is clearly more efficient (because not using autoreleasepools) than:
>
> NSString *s = [ NSString stringWithFormat: ...];
> [ someCollection addObject: s ];
>
> But what about Arc?
> Is the compiler clever enough to make both versions equally efficient?

Maybe.  You can't know if the NSString implementation was itself compiled with ARC.  If it was, then there is a *possible* optimization that can avoid the autorelease+retain.  However, you can't rely on this.

> Or should one still avoid using the convenience method stringWithFormat: ?

Are you programming for iOS?  The recommendation for that is still to avoid autoreleased objects so as to keep the high-water mark of memory usage down.  For Mac OS X it's never been that big a concern except for code in a loop or the like.

Regards,
Ken


_______________________________________________

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: 
 >Arc and autorelease (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Re: stringWithFormat / Rendering Text (iOS)
  • Next by Date: Re: NSWindowController subclasses, and retain cycles
  • Previous by thread: Arc and autorelease
  • Next by thread: Re: Arc and autorelease
  • Index(es):
    • Date
    • Thread