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

An Objective-C programmer's responsibility


If you have experience in other programming languages, such as Java, and are coming to Objective-C now, forget about constructors, they don't exist in Objective-C. Constructors are language-level constructs that merge the allocation and initialization actions, but they have restrictions:

  • They don't return anything. While the Objective-C class initialization method, + (void) initialize, does not return anything, the default—(id) init method of an Objective-C class returns an object of the type id.

  • The constructor's name must be identical with the class.

  • When you call the superclass, being the first statement is a must.

The last point ensures you won't deal with garbage data, but this is a restriction. In Objective-C, as in C, without this restriction, you, the programmer, have more flexibility and power, but it is also your responsibility to deal with garbage data.