O'Reilly logo

Objective-C Phrase Book, Second Edition by David Chisnall

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required