开发者

Memory leaks destroying my application?

开发者 https://www.devze.com 2023-02-28 09:59 出处:网络
I\'m in big trouble now, my iPhone application keep terminating again and again due to memory leaks and I am开发者_如何学Go unable to judge that where are those leaks. Tell me what step can I take in

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

Thanks


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/


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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号