Automatic Reference Counting for Objective-C

Hi All,

I'm happy to say that we just pushed the Clang implementation of Automatic Reference Counting (ARC) for Objective-C into the public http://clang.llvm.org repository, including the low-level ARC migration tool.

ARC provides automated memory management for Objective-C programs that is compatible with existing retain/release code. ARC is carefully built to be a reliable programming model that errs on the side of producing a compiler error instead of silently producing a runtime memory problem. ARC automates Objective-C objects, not malloc data, file descriptors, CoreFoundation datatypes or anything else.

In addition to ARC, this code also includes compiler support for Zeroing Weak References, which build on top of ARC to provide a language feature useful for breaking retain cycles.

For more detail than you probably want about ARC, please check out the spec:
http://clang.llvm.org/docs/AutomaticReferenceCounting.html

While this is mostly useful for people with access to previews of iOS5 orMac OS X Lion (which provide the necessary runtime support for ARC) and Xcode 4.2 (which provides high level tools), we encourage you to take a look, play with it, report bugs etc. If you have feedback or proposals for how to change the model, please familiarize yourself with the spec before making wild new suggestions :slight_smile:

If you're a registered Apple developer, ARC is now considered a public feature of Clang (also known as "Apple LLVM Compiler" in Xcode), so it can be discussed publicly. However, interactions with other prerelease features of iOS5 or Lion are considered confidential until those products launch, so please refrain from disclosing non-ARC details. Thanks!

-Chris

Are the semantics of the runtime support functions documented somewhere? The code seems to reference them by name in the runtime-agnostic part of clang, but doesn't specify what they actually do.

David

I'll write them up.

John.

I've documented them in r133385; let me know if the documentation is unclear.

John.

That's great, thanks. It was clear enough to implement all of the functions. We now have a working (not optimised) implementation of ARC in GNUstep - I'm looking forward to playing with it.

On a semi-related note, I could only find the command-line options for running the ARC migration tool by looking through the source code. Are these supposed to be documented somewhere? And is there a reason they use arr instead of arc in the names, or was that a typo?

David

I've documented them in r133385; let me know if the documentation is unclear.

That's great, thanks. It was clear enough to implement all of the functions. We now have a working (not optimised) implementation of ARC in GNUstep - I'm looking forward to playing with it.

Great.

On a semi-related note, I could only find the command-line options for running the ARC migration tool by looking through the source code. Are these supposed to be documented somewhere? And is there a reason they use arr instead of arc in the names, or was that a typo?

The migration tool isn't expected to be generally useful outside of Xcode, and the interfaces continue to change and evolve over time. ARR was an earlier name for the feature before we standardized on ARC. Expect change in the migrator, don't get too comfortable with it :slight_smile:

-Chris

Not only the migrator uses it. The __has_feature tag use to detect if arc is enabled used arr too (it is objc_arr).

-- Jean-Daniel

Yes, but it will be removed. Please use __has_feature(objc_arc) instead.

-Chris

Yes. I noticed after positing this message that objc_arc was already defined in clang and even documented on the clang web site.

-- Jean-Daniel