• 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: Is "-init" really needed?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is "-init" really needed?


  • Subject: Re: Is "-init" really needed?
  • From: Alastair Houghton <email@hidden>
  • Date: Thu, 10 Aug 2017 15:44:32 +0100

On 10 Aug 2017, at 15:24, Jeremy Hughes <email@hidden> wrote:
>
>> On 10 Aug 2017, at 15:15, Alastair Houghton <email@hidden>
>> wrote:
>>
>> On 10 Aug 2017, at 15:09, Charles Srstka <email@hidden> wrote:
>>>
>>> They’re equivalent syntactically, but performance-wise, +array and friends
>>> will cause the object to be put into an autorelease pool. Therefore, +new
>>> is better for performance.
>>
>> Not with ARC they don’t.  The ARC logic circumvents the autorelease pool in
>> that case.
>
> Are you sure?

Yes, I’m sure.  At the call site, ARC causes the compiler to emit a call to
objc_retainAutoreleasedReturnValue() or
objc_unsafeClaimAutoreleasedReturnValue(), while in the method itself, ARC will
use objc_autoreleaseReturnValue() or objc_retainAutoreleaseReturnValue().  The
latter looks at the code for the call site and, assuming it matches, it will
*not* do the autorelease and will set a flag that causes
objc_retainAutoreleasedReturnValue() to eliminate the retain.

> We had a discussion about autorelease pools recently, and it seems that
> they’re still used by Cocoa APIs (to support ARC and non-ARC code).

Yes, autorelease pools still exist and are still used.  Not all code uses ARC,
and for the above optimisation to happen, the code needs to use the functions
mentioned, which will only happen if either (a) it’s compiled with ARC, or (b)
those calls are used explicitly.  You can see the code for this in the
Objective-C runtime code, <here:
https://opensource.apple.com/source/objc4/objc4-709/runtime/objc-object.h.auto.html>
 (search for SUPPORT_RETURN_AUTORELEASE).

Kind regards,

Alastair.

--
http://alastairs-place.net

_______________________________________________

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: Is "-init" really needed?
      • From: Charles Srstka <email@hidden>
References: 
 >Is "-init" really needed? (From: David Hoerl <email@hidden>)
 >Re: Is "-init" really needed? (From: Jens Alfke <email@hidden>)
 >Re: Is "-init" really needed? (From: じょいすじょん <email@hidden>)
 >Re: Is "-init" really needed? (From: Carl Hoefs <email@hidden>)
 >Re: Is "-init" really needed? (From: Uli Kusterer <email@hidden>)
 >Re: Is "-init" really needed? (From: email@hidden)
 >Re: Is "-init" really needed? (From: Doug Hill <email@hidden>)
 >Re: Is "-init" really needed? (From: Alastair Houghton <email@hidden>)
 >Re: Is "-init" really needed? (From: Doug Hill <email@hidden>)
 >Re: Is "-init" really needed? (From: Alastair Houghton <email@hidden>)
 >Re: Is "-init" really needed? (From: email@hidden)
 >Re: Is "-init" really needed? (From: Alastair Houghton <email@hidden>)
 >Re: Is "-init" really needed? (From: Charles Srstka <email@hidden>)
 >Re: Is "-init" really needed? (From: Alastair Houghton <email@hidden>)
 >Re: Is "-init" really needed? (From: Jeremy Hughes <email@hidden>)

  • Prev by Date: Re: Is "-init" really needed?
  • Next by Date: Re: Is "-init" really needed?
  • Previous by thread: Re: Is "-init" really needed?
  • Next by thread: Re: Is "-init" really needed?
  • Index(es):
    • Date
    • Thread