简体   繁体   中英

iOS UITableView random crash

I have a problem I can't locate clearly, maybe you can help me...

I have an iPad project, based on UINavigationController, most (but not all) of controllers inside are instances of UITableViewController, and everything works well...

Everything excepting that my application crashes randomly, sometimes after 10 minutes of use, sometimes after only 10 seconds... It never crashes on the same view, never at the same time, making that difficult to reproduce.

In addition, it only seams to happen on device, I've never got this crash in the simulator.

The debugger doesn't help me very much, here is what it says: -[UITableView autorelease]: message sent to deallocated instance 0x8e9800

And here is the call stack: http://i.stack.imgur.com/JSCHx.png

Any idea ? Thanks (and sorry for my english)

You're overreleasing a UITableView somewhere in your code. Are you calling release or autorelease on the UITableView inside one of your UITableViewControllers? You should only release objects that you 'own'. You get to own an object by using methods beginning with alloc , new , copy , or retain .

Please read the cocoa memory management guidelines for more info.

Useful links:

http://www.cocoadev.com/index.pl?MemoryManagement

http://www.cocoadev.com/index.pl?RulesOfThumb

在某个时候,您要么释放一个您不拥有的UITableView实例,要么在retain对它的引用的某个时刻无法retain它(例如,将其存储在ivar或声明为assign的属性中而不是保留)。

I have written about how to debug things like this on my blog:

http://loufranco.com/blog/files/Understanding-EXC_BAD_ACCESS.html

Basically, try these three things first:

  1. Do a Build an Analyze and fix everything you see
  2. Turn on Zombies, run your code -- it will tell you if you talk to dealloced objects
  3. If that fails, try Debug Malloc, but that's way harder.

I apologize, after re-reading all my source code, I found ONE ViewController (I have around 20 ViewController), where I released an Outlet, in ViewDidUnload.

The reason that it crashed randomly is that I didn't understood well the mechanism of ViewDidUnload, it is called to release views (but not objects of controllers) when memory is low and view is not visible (ex: First ViewController of a NavigationController), and the views are re-loaded when the ViewController become visible again...

In simulator, memory is rarely an issue so ViewDidUnload is almost never called...

Problem fixed, thank you everyone for your help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM