Please suggest the best way of solving memory leaks on the iphone. What is the best use of release, autorelease, retain and which cases do each apply?
You can track memory leaks with Instruments: see this tutorial.
If you're familiar with Valgrind, you use it on x86 binaries built against the iPhone Simulator SDK: see how Landon Fuller does it.
EDIT: Another Stackoverflow answer suggests the Clang analyser: static analysis of the code may detect memory allocation errors as well. I never used this tool myself but it's good to know it's possible.
There's Apple's Instruments.app in your /Developer/Applications folder, which is intended to test appplications for leaks and other errors.
I believe you will find a good tutorial.
This is a very broad question. I'd start with Apple's Memory Management Programming Guide for Cocoa.
There are many questions here which point to various memory management resources. These include
- Memory Management in Objective-C
- Understanding reference counting with Cocoa / Objective C
- iPhone Development - Lessons in memory management
- Memory leak detection tools in XCode
- How do you detect memory leaks on iPhone?
- IPHONE: Analyzing leaks with instruments
- iPhone development - preventing leaks
- In CocoaTouch (iPhone OS) how do I find/eliminate leaks that the Instruments Leak tool doesn’t find?