Mac Dev Center: Memory Management Programming Guide for Cocoa: Memory Management Rules
Just a friendly little reminder of the memory management rules in Objective-C, since they seem to always cause so much confusion, despite being so simple:
This is the fundamental rule:
You take ownership of an object if you create it using a method whose name begins with “alloc” or “new” or contains “copy” (for example,
alloc,newObject, ormutableCopy), or if you send it aretainmessage. You are responsible for relinquishing ownership of objects you own usingreleaseorautorelease. Any other time you receive an object, you must not release it.
It really does surprise me that even with rules this simple, there are still developers that throw up their hands in the air and cry out for garbage collection. If you think this is difficult, go try managing memory in C or C++.