O'Reilly logo

The Complete Idiot's Guide® To iPad and iPhone App Development by Troy Brant

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

Golden Rules of Memory Management

So now that you know about alloc/init, retain/release, and autorelease, it’s time to go over two of the golden rules of memory management.
1. If you retain it, you release it. Use the NARC rule to determine if you have retained an object. The NARC rule states that each time you call the following methods, you must call release or autorelease to match:
+new: new is a convenience method that combines alloc/init into a single call. alloc/init is used much more heavily in iPhone development, however.
+alloc: alloc is used in the alloc/init pattern.
-retain:retain increases the reference count for an object by 1.
-copy:copy, for objects that support it, creates a new instance of the object that has the same ...

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