Book Image

Objective-C Memory Management Essentials

Book Image

Objective-C Memory Management Essentials

Overview of this book

Table of Contents (18 chapters)
Objective-C Memory Management Essentials
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

A memory model in Objective-C


A very significant improvement in Objective C 2.0 is its memory model. The countless remnants of problems from the first Objective-C implementations as a preprocessor that induced C were cleaned up. In older versions, Objective-C objects were simply C structures, containing a pointer to their classes in their first fields, and its pointers were just able to receive messages when you wanted to send them.

Now every object pointer comes into one of the following categories: weak, strong, autoreleasing, and unsafe unretained. When ARC is disabled, the programmer is responsible to take care of them all, being sure that they are all safe, for the reason that all those pointers just fit the last category.

The default category (type qualifier) is a strong pointer; they are largely correspondent to the consequences of writing flawless defensive retain/release code. Assigning to a strong pointer is relative to retain the new value and release the old value, because owning...