简体   繁体   English

iOS UITableView随机崩溃

[英]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... 我有一个基于UINavigationController的iPad项目,其中的大多数(但不是全部)控制器都是UITableViewController的实例,并且一切正常。

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. 除了我的应用程序随机崩溃之外,所有东西有时都会崩溃,有时是在使用10分钟之后,有时只是在10秒之后……它永远不会在同一视图上崩溃,也不会在同一时间崩溃,从而难以复制。

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 调试器对我没有太大帮助,它说的是: -[UITableView autorelease]:发送到已释放实例0x8e9800的消息

And here is the call stack: http://i.stack.imgur.com/JSCHx.png 这是调用堆栈: http : //i.stack.imgur.com/JSCHx.png

Any idea ? 任何想法 ? Thanks (and sorry for my english) 谢谢(对不起我的英语)

You're overreleasing a UITableView somewhere in your code. 您在代码中的某个地方过度释放了UITableView。 Are you calling release or autorelease on the UITableView inside one of your UITableViewControllers? 您是在其中一个UITableViewController内的UITableView上调用release还是autorelease release You should only release objects that you 'own'. 您只应释放“拥有”的对象。 You get to own an object by using methods beginning with alloc , new , copy , or retain . 你自己使用的方法与开头的对象allocnewcopy ,或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?MemoryManagement

http://www.cocoadev.com/index.pl?RulesOfThumb 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 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. 如果失败,请尝试Debug Malloc,但这要困难得多。

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. 很抱歉,重新阅读所有源代码后,我在ViewDidUnload中找到了一个ViewController(我有20个左右的ViewController),并在其中发布了一个Outlet。

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... 它随机崩溃的原因是我不太了解ViewDidUnload的机制,在内存不足且视图不可见时调用它来释放视图(但不是控制器的对象)(例如:NavigationController的First ViewController) ,然后在ViewController再次变得可见时重新加载视图。

In simulator, memory is rarely an issue so ViewDidUnload is almost never called... 在模拟器中,内存很少成为问题,因此几乎从未调用过ViewDidUnload ...

Problem fixed, thank you everyone for your help 问题已解决,谢谢大家的帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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