views:

345

answers:

3

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?

+6  A: 

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.

Gregory Pakosz
+1: for suggesting Valgrind :D
Kornel Kisielewicz
+1  A: 

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.

Jacek
Instruments is the way to go. It can tell you exactly which line leaked the memory.
Mike Weller