It's not really that difficult. Here's some rules of thumb that will go a LONG way.
- Release all properties in the
dealloc (unless they are set to "assign").
- If you "alloc" "new" or
"copy" in your initialization, you
probably need to "release" in the
dealloc.
- If you "alloc" "new" or
"copy" at the beginning of a method,
you probably need to "release" at the
end of the method.
- If you "alloc"
"new" or "copy" something to put in
an Array, Set, or Dictionary, go
ahead and release it... the
collection will retain it without any
help from you. (I am not a big fan of
autorelease, but this is a pretty
decent situation for its use. Create
the object autoreleased, then add it
to the collection. Done.)
These are really rough rules of thumb, and I'm sure everyone can come up with exceptions to these rules, but these will go a long way toward getting you allocating and releasing memory the right way.
For the rest of the way, run your code with the Leaks instrument often. Fix problems AS YOU FIND THEM. It's much easier to fix it now than it is to fix it in a month, when you don't remember why you wrote the code that way.
And finally... it's rare, but Apple code DOES sometimes leak. The Leaks instrument should tell you exactly what is being leaked. If it doesn't look like something you are doing, it's POSSIBLE that it's not. As a concrete example: Core Data for the iPhone leaks small amounts of RAM upon (I think) creating a new ManagedObjectContext. Might be when you do a fetch, though, I can't remember right off the top of my head.