Game Development Reference
In-Depth Information
Now, the compiler has taken over the tedious job of retaining and releasing objects in
memory, and all the source code throughout the topic has been converted to use ARC.
This means fewer code lines to write, and fewer potentially lethal drugs . . . err, bugs.
The two biggest concerns from Objective-C programmers towards ARC are loss of
control and learning a new programming paradigm. Both are terrible arguments against
using ARC. I offer an analogy: think of ARC being like automatic transmission in a
car, and manual reference as shifting gears manually. If you leave the world of the
clutch and gear stick, are you really giving up control? Yes, but it's not control that you
really need. Do you need to learn something new? No, you only need to unlearn a few
things and you actually have to do less.
With manual transmission, you can easily miss a gear even after years of driving, pos-
sibly damaging the engine. That is equivalent to over-releasing or over-retaining an ob-
ject. You may also kill the engine with the clutch every now and then. That's the equi-
valent of crashing your app due to a dangling (over-released) pointer. And with an
automatic transmission, the engine always changes gears at the optimal rate, typically
reducing the fuel consumption rate to a comparable manually shifted car (and a typical
driver). Wasting gas is the equivalent of leaking memory.
To sum it up: ARC does not take control away from you. You can still control
everything that is important to your app. Code that requires more memory management
control than is available to you under ARC does not exist. The issue of loss of control
is purely psychological and possibly based on misconceptions about how ARC works.
Which brings me to the learning aspect: yes, there are a few things you can and should
learn about ARC. But this is so little compared to what a programmer learns every day,
and it's far easier than picking up (let alone mastering) manual reference counting if
you're new to Objective-C. You only need to read Apple's relatively short Transition-
ing to ARC Release Notes summary: http://developer.apple.com/lib-
rary/ios/#releasenotes/ObjectiveC/RN-TransitioningToARC/
Introduction/Introduction.html . You may also want to read my blog post
covering everything you need to know about automatic reference counting:
www.learn-cocos2d.com/2011/11/everything-know-about-arc .
Why Use cocos2d for iOS?
Search Nedrilad ::




Custom Search