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?
4 Answers
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.

- 1
- 1

- 69,011
- 20
- 139
- 164
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?

- 1
- 1

- 170,088
- 45
- 397
- 571
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.

- 1,894
- 5
- 21
- 34
-
Instruments is the way to go. It can tell you exactly which line leaked the memory. – Mike Weller Jan 16 '10 at 12:42