Chapter 5: Memory Management with Objective-C ARC
The shift from the GCC compiler to the LLVM compiler gave Apple control over certain language and compiler-specific features. One arguably important feature is Automatic Reference Counting (ARC). For the most part, ARC “just works.” On a new project, things are easy, but when you try to migrate an existing code base to use Objective-C ARC, you will probably find that the road is long and winding.
In Chapter 2, I showed you how to use Xcode’s built-in Objective-C ARC migration tool. In this chapter, I show you how to migrate your code base to ARC and solve the most commonly faced errors by finding out how ARC works. Let’s get started.
Introduction to Objective-C ARC
In a nutshell, ARC is a memory management model where the compiler automatically inserts retains
and releases
appropriately for you. This means that you don’t have to worry about managing memory and focus or writing the next great app. You’re relieved from worrying about leaks, for the most part.
A Brief History
Prior to ARC, Apple platform developers used manual reference counting memory management on iOS. On Mac, developers had a choice. They could choose either garbage collection memory management or manual reference counting memory management. Garbage collection is mostly a high-level language (C# or Java) feature that non-deterministically manages memory for you. A programming language is designed either for writing high-performance applications or for writing ...