Re: Is "-init" really needed?
Re: Is "-init" really needed?
- Subject: Re: Is "-init" really needed?
- From: John McCall <email@hidden>
- Date: Thu, 10 Aug 2017 11:34:01 -0400
> On Aug 10, 2017, at 11:13 AM, Charles Srstka <email@hidden> wrote:
>> On Aug 10, 2017, at 9:44 AM, Alastair Houghton
>> <email@hidden> wrote:
>>
>> On 10 Aug 2017, at 15:24, Jeremy Hughes <email@hidden
>> <mailto:email@hidden>> wrote:
>>>
>>>> On 10 Aug 2017, at 15:15, Alastair Houghton <email@hidden
>>>> <mailto:email@hidden>> wrote:
>>>>
>>>> On 10 Aug 2017, at 15:09, Charles Srstka <email@hidden
>>>> <mailto: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.
>
> The frameworks (and thus, the implementation of +array) are not built using
> ARC. The -autorelease method is called manually, and the object is put in the
> autorelease pool. You can see this for yourself by making a small test app
> that calls [NSMutableArray array] and running it in Instruments, where the
> autorelease will be clearly visible.
Autoreleases done by -autorelease can still be reclaimed by
objc_retainAutoreleasedReturnValue.
The autorelease-reclaim optimization is not reliable, and there are a number of
caveats that make testing it tricky. That is why we generally refer to it as
an optimization, rather than claiming it as a semantic guarantee. In your test
app, you are almost certainly running into a well-known problem where the first
attempt to reclaim an autorelease fails on x86-64 (because of a detail of
dynamic linking).
John.
_______________________________________________
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