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

Inheritance


To understand inheritance, think about it as a perfect biological tree, where you have inherited some behavioral traits from your father, but more than that you have your own. Something like this happens in Objective-C when a class is inherited from another.

Basic samples are the classes whose names start with NS provided by Cocoa and Cocoa Touch, such as NSString, NSArray, and NSDictionary. They are all inherited from NSObject. Each of them has their particular methods to handle the different types of contents they hold, but everyone shares methods such as alloc and init. These two class methods, inherited from NSObject, respectively allocate memory and initialize the object:

The alloc method will rarely be overridden, performing a single task and allocating memory to the object being created. However, another inheritance example is the init method, which is also inherited from NSObject. It received modifications in each child class, creating other initialization methods to quickly...