[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Automatic Reference Counting

From: David Chisnall
Subject: Re: Automatic Reference Counting
Date: Thu, 7 Jul 2011 20:55:44 +0100

Ooops, forgot to CC: the list:

On 7 Jul 2011, at 19:23, Ivan Vučica wrote:

> Hi,
> I just read this, so I have a couple of questions :-)
> On Wed, Jun 29, 2011 at 15:36, David Chisnall <address@hidden> wrote:
> ARC does some quite nice things for you.  For every assignment, the compiler 
> will automatically insert calls to runtime functions that do the retain / 
> release juggling for you.  It will also implicitly add code to your objects 
> freeing all instance variables.  Because of this, some things are not allowed 
> in ARC mode:
> - Implementing -retain, -release, or -autorelease
> - Calling -retain, -release, or -autorelease
> - Storing object pointers that are not __unsafe_unretained qualified in 
> structures.
> If calling -retain, -release and -autorelease is not allowed, how is it 
> possible to mix ARC with non-ARC code? Does the compiler throw a warning, an 
> error, or the thing just silently doesn't work?

You can only mix them in separate compilation units, you can't mix them within 
the same source file.  The compiler will reject any code that explicitly calls 
any of these methods in ARC mode.  In non-ARC mode, it will permit them and 
will not insert the barrier functions.

> What happens when -retain, -release and -autorelease are overridden?

This is not allowed in ARC compilation units.  My ARC implementation will call 
them if the class declaring them does not explicitly opt in to ARC (see README 
for how to do this).  Not sure about Apple's.

> What happens when non-__unsafe_unretained pointers are stored in structure? 
> Does it silently crash?

The compiler rejects the code.  

> Are all pointers __strong by default?

All object pointers, yes.

> What happens with non-Objective-C pointers, such as results of SDL functions?

Nothing.  ARC only affects objects.  Other pointers are treated just as they 
are in C.

> Will I have any problems using SDL if ARC is used in same codebase?

Not unless you are passing objects to SDL code (e.g. for callbacks) without 
calling CFRetain() on them.


-- Sent from my Difference Engine

reply via email to

[Prev in Thread] Current Thread [Next in Thread]