Since so many questions come up on this topic I thought I would give a quick summary on the basic rules of iPhone memory management. More specifically about when you should release an object.
Here's the simplest rule: If you directly call any of the following methods on an object then you must call release on the object:
alloc/init
retain
copy
mutableCopy
If you write a method that needs to return an object created with one of the above methods then your return value should look something like this:
Code:
return [result autorelease];
This allows your method to fulfill its obligation to release as required but the release won't happen until a little later so the code that calls this method has an opportunity to retain the result if required.