rptwsthi
rptwsthi

Reputation: 10172

Memory leaks destroying my application?

I'm in big trouble now, my iPhone application keep terminating again and again due to memory leaks and I am unable to judge that where are those leaks. Tell me what step can I take in order to resolve this problem.

Thanks

Upvotes: 0

Views: 388

Answers (4)

Tejaswi Yerukalapudi
Tejaswi Yerukalapudi

Reputation: 9157

You could also Build + Analyze your application in XCode itself (Cmd+Shft+A or Product > Analyze). It'll show you the more obvious leaks.

Upvotes: 0

darshansonde
darshansonde

Reputation: 501

If you need to find out leaks and source of crash. you can try these

  1. try to find as many leaks as possible from Instruments and fix
  2. set NSZombieEnabled for your executable parameters and debug application crash
  3. change all your autorelease objects to use alloc init as much as possible.

-- 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.

Upvotes: 0

lxt
lxt

Reputation: 31304

I think you're confusing terminology here. A memory leak is when you don't release an object after you're done with it.

A leak won't directly cause a crash. 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 not 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 over releasing), in which case your instruments leaks tool isn't going to help you.

Upvotes: 3

Daniel A. White
Daniel A. White

Reputation: 190945

You can use Instruments to see where potential leaks are.

Here is a good tutorial. http://mobileorchard.com/find-iphone-memory-leaks-a-leaks-tool-tutorial/

Upvotes: 4

Related Questions