[cfe-dev] ARC and @synthesize of read only property

Jean-Daniel Dupas devlists at shadowlab.org
Thu Jul 21 23:56:20 PDT 2011


Le 20 juil. 2011 à 10:57, David Chisnall a écrit :

> On 19 Jul 2011, at 21:06, Jean-Daniel Dupas wrote:
> 
>> Thank you for the explanation. So the retained/autorelease is a new behavior introduced with ARC. AFAIK, the getter did this only for atomic properties in non ARC mode.
> 
> You can check the generated IR.  In ARC mode, it calls objc_getProperty() for atomic properties.  For  nonatomic properties, it accesses the ivar directly and calls objc_retainAutoreleaseReturnValue().  If you do something like:
> 
> id o = [object synthesizedNonatomicProperty];
> 
> Then ARC will translate this into something like:
> 
> o = objc_retainAutoreleasedReturnValue([object synthesizedNonatomicProperty]);
> 
> This skips the autorelease pool, so the object is now retained in the caller but not present in the autorelease pool.  ARC will then objc_release() it at the end of the scope of o.  This means that you get a lot less redundant autorelease pool churn in ARC mode.

Look like commit 135747 changed this behavior for nonatomic (and non-weak) property. They now have the same behavior in ARC mode than in non-ARC mode. They are simply returned.

-- Jean-Daniel








More information about the cfe-dev mailing list