One of the new developer APIs presented at WWDC was something called Automatic Reference Counting. This term also was on this slide visible during the Keynote, so it’s no longer a secret.
ARC might just be the single piece of technology which excited WWDC attendees the most. We cannot discuss the details of what was presented during the conference, but there is already quite a bit of public information available. Enough to get every iOS developer excited.
There are basically two modes of memory management:
- Garbage Collection – frequently a process – the garbage collector – scans for objects that are not used any more and those are freed
- Reference Counting – each object has a counter that gets increased whenever another object needs it and decreased when it no longer needs it. Objects are freed when their counter reaches 0.
The former is the prevalent mode in desktop systems. The latter is what we use in Objective-C nowadays, with the addition of autorelease pools which might be seen as sort of a manual garbage collection done every time the run loop is entered: all objects marked for autoreleased are sent a release once. This way you don’t have the overhead of walking through all objects, but still you have a bit less to worry about.
The technical explanation of what ARC is can be found in the official CLANG LLVM ARC documentation. It summarizes it like this:
Automatic Reference Counting implements automatic memory management for Objective-C objects and blocks, freeing the programmer from the need explicitly insert retains and releases.
Yes, you see it right! No more retains and releases! Isn’t that fabulous?
ARC adds “Automatic” to the process of reference counting so that we don’t have to worry about it any more. Think of what Build&Analyze already does when it shows you where you are overreleasing or underretaining something. The think how great it would be if it would actually also correct your code automatically. ARC does exactly that and quite a few things more.
Think of ARC like the movie coming next year where just seeing the trailer gets you excited. Awesome special effects! Cool story! Great acting. And so much more that the trailer cannot give away all of the plot.
Those are the items that we cannot discuss: when or how Apple will enable ARC for public use and discussion. It might or might not be in a future version of a compiler or development tool … if you catch my drift. But putting it in this front and center position of the above mentioned slide tells us developers that ARC will be daily business for us once we get to develop solely for iOS 5.
I think that it’s rather “typically Apple”: if you have two technologies that both have their indy-vidual advantages and drawbacks, then Apple will just go and invent a third option that has only advantages. One of the more immediate ones will mean that most iOS development courses can be one day shorter because we no longer have to explain retain/release to beginners. “It just works!”
ARC is one of the new technologies that make me wish that I can soon switch to only be developing on iOS 5. I don’t know yet if you will also be able to build for iOS 4 with ARC. May be, may be not. Please comment if you know more that’s not under NDA.
Thank you to Lukas and Joshua for providing the two movie posters I’ve included in this article. Both are accomplished designers of iOS apps, and were incredibly fast in implementing my ideas. You should contact them via the provided links if you need their services.