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