Transitioning to ARC

17 August 2012, 16:57

Over a year ago, Apple released Automatic Reference Counting, a new technology that pretty much relieves developers of one of the Objective-C/iOS duties that caused the most fear and loathing: memory management.

Supported on iOS4 (for the most part) and iOS5 (fully), ARC allows the developer to leave the business of deciding where and when to ‘release’ or ‘retain’ Objective-C objects to the compiler, which will insert the appropriate calls by itself.

The technology is well-documented elsewhere.

With the 2.2.0 release of TPE for iOS, we added in automated crash reporting by Crittercism.

It turned out to be quite an eye opener.

With the 2.2.0 release we were seeing around 1.5% of app loads crashing, particularly affecting iPad 1 owners – way higher than I’d ever imagined it would be, and far from acceptable.

The most frequent crash would occur on a memory warning, with a message being sent to a deallocated object – a classic instance of memory management gone wrong.

On seeing the stats, we quickly updated TPE to use ARC and released a 2.2.1 update. Since then, the crash rate has reduced to <0.5% of app loads, of which over half are caused by a bug introduced by mistake (my wrist resting on the space bar, I think!).

Pretty much all the memory-related crashes we saw reported in 2.2.0 are gone.

TPE consists of around 55,000 lines of code – not huge, but non-trivial – and so the migration to ARC was something to be considered carefully, especially given the high stakes game that is an App Store update.

However, I’m pleased to say the process was straightforward and has significantly improved the quality of the app.

As this post says:

There is no downside. Use it. Do it today. It is faster than your old code. It is safer than your old code. It is easier than your old code.



(will not be displayed)