So we trust you can’t possibly have missed so far the impending debut of Automatic Reference Count technology:
Automatic Reference Counting (ARC) for Objective-C makes memory management the job of the compiler. By enabling ARC with the new Apple LLVM compiler, you will never need to type retain or release again, dramatically simplifying the development process, while reducing crashes and memory leaks. The compiler has a complete understanding of your objects, and releases each object the instant it is no longer used, so apps run as fast as ever, with predictable, smooth performance.
Well, that sounds pretty magical, doesn’t it? A little too magical, doesn’t it sound like? Well, whilst we wait for WWDC session videos to show up, here’s some not so light reading for you on the Clang website:
The first and primary purpose of this document is to serve as a complete technical specification of Automatic Reference Counting… The secondary purpose is to act as a rationale for why ARC was designed in this way. This should remain tightly focused on the technical design and should not stray into marketing speculation.
Ah, yes. Definitely wouldn’t want to stray into marketing, indeed.
…The primary advantage of GC over ARC is that it collects retain cycles. A secondary advantage is that “retained” assignments are “atomic” because they are a simple store.
ARC has several big advantages over libauto GC:
1. It has deterministic reclamation of objects (when the last strong reference to the object goes away) where GC frees an object “sometime later”. This defines away a class of subtle bugs that can exist in GC apps that aren’t exposed because the collector doesn’t trigger “in the buggy window”.
2. The high water mark is generally much lower with ARC than GC because objects are released sooner.
3. libauto provides a fragile programming model, you have to be careful to not lose write barriers etc.
4. not all of the system frameworks are GC clean, and the frameworks do occasionally regress as they evolve.
5. ARC doesn’t suffer from false roots. libauto conservatively scans the stack, which means that integers that look like pointers can root object graphs.
6. ARC doesn’t have anything that kicks in and stops your app, causing UI stutters. libauto is pretty advanced as far as GC implementations go because it doesn’t immediately stop every thread, but it still does usually end up stopping all the UI threads.
Yeah, that adds up to a pretty good case for adopting ARC for any project without a 3.x runtime requirement, we’d say. And if like the fellow in the above thread you are a big GC fan, well the comment
I don’t have any comment on GC, other than we continue to support it on Lion.
sure makes it sound like “the writing’s on the wall” to us!
Clang Source Annotations has tips for dealing with annoyingly named annoyances.Continue Reading →