I'm in big trouble now, my iPhone application keep terminating again and again due to <strong>memory leaks</strong> and I am unable to judge that where are those <strong>leaks</strong>. Tell me what step can I take in order to resolve this problem.
I think you're confusing terminology here. A memory <strong>leak</strong> is when you don't release an object after you're done with it.
A leak <strong>won't directly cause a crash</strong>. Leaks can indirectly cause crashes if you run out of memory as a result of not releasing lots of objects. However, if your crashes are happening in the simulator as well this is almost certainly not the case (the simulator having far more available memory than the device). As Daniel says, you can use the instruments tool to find out what's leaking.
Another good method is to use the XCode static analyzer - you can have it analyze your code and detect most common leaks.
Now, if your app is crashing and it's <em>not</em> because of a memory leak (you'll be able to tell this because you'll have memory warnings outputting to the console) then chances are your problem isn't a leak. Perhaps it's a bad access (you're <em>over</em> releasing), in which case your instruments leaks tool isn't going to help you.Answer2:
You can use Instruments to see where potential leaks are.
Here is a good tutorial. <a href="http://mobileorchard.com/find-iphone-memory-leaks-a-leaks-tool-tutorial/" rel="nofollow">http://mobileorchard.com/find-iphone-memory-leaks-a-leaks-tool-tutorial/</a>Answer3:
If you need to find out leaks and source of crash. you can try these<ol><li>try to find as many leaks as possible from Instruments and fix</li> <li>set NSZombieEnabled for your executable parameters and debug application crash</li> <li>change all your autorelease objects to use alloc init as much as possible.</li> </ol>
-- worst resort is if it keeps crashing even after trying all the above three. you write memory intensive module of your code in a thread and clean up that thread. I've noticed usually when threading is done the memory footprints are much cleaner. This is just my opinion, but the above 3 you should do.Answer4:
You could also Build + Analyze your application in XCode itself (
A or Product > Analyze). It'll show you the more obvious leaks.