3. Memory Management

If you come from a C or C++ background, you’re probably used to tracking ownership of objects and manually allocating and destroying them. If you’re coming from a language such as Java, you’re probably accustomed to having the garbage collector take care of all of this for you.

Objective-C does not, at the language level, provide anything for allocating or deallocating objects. This is left up to C code. You commonly allocate objects by sending their class a +alloc message. This then calls something like malloc() to allocate the space for the object. Sending a -dealloc message to the instance will then clean up its instance variables and delete it.

The Foundation framework adds reference counting to this simple manual memory ...

Get Objective-C Phrase Book, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.