现在的位置: 首页 > 综合 > 正文

EXC_BAD_ACCESS 解决办法

2012年09月21日 ⁄ 综合 ⁄ 共 1991字 ⁄ 字号 评论关闭

http://stackoverflow.com/questions/327082/exc-bad-access-signal-received

 

A major cause of EXEC_BAD_ACCESS is from
trying to access release objects.

To find out how to troubleshoot this, read this document:
DebuggingAutoReleasePool

Even if you don't think you are "releasing auto-released objects",
this will apply to you.

This method works extremely well. I use it all the time with great
success!!

In summary, this explains how to use Cocoa's NSZombie debugging class
and the command line "malloc_history" tool to find exactly what
released object has been accessed in your code.

Sidenote:

Running Instruments and checking for leaks will not help troubleshoot
EXEC_BAD_ACCESS. I'm pretty sure memory leaks have nothing to do with
EXEC_BAD_ACCESS. The definition of a leak is an object that you no
longer have access to, and you therefore cannot call it.

 

 

 

 

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

 

 

http://www.cnblogs.com/mac_arthur/archive/2010/04/09/1708364.html

 

debug-exc_bad_access-on-iphone

当程序出现“EXC_BAD_ACCESS”时,就像不解风情的妻子对你说:“亲爱的,今晚不行”。这两种情况都是非常不幸的。

让我们先看看EXC_BAD_ACCESS到底是什么。

向已经释放的对象发送消息时会出现EXC_BAD_ACCESS。当出现错误时,通常会调用堆栈信息,特别是在多线程的情况下。

怎样提供一个dummy,当释放一个对象导致程序终止时,在堆栈上告诉我们错误信息,好,下面我们将告诉你怎么去做。

如果你设置了NSZombiEnabled环境变量,当销毁一个对象时,objective的运行时环境会在这个对象后边设置一个dummy,当
调用这个对象的方法时,程序会终止,并在堆栈上显示错误信息,下边教你怎么设置NSZombiEnabled

首先,在Xcode中打开executables


查看其中内容的信息。

然后,打开信息面板中的Arguments面板


点击左下角的加号,添加变量NSZombiEnabled,并将变量的值设置为YES。

重新运行程序,当过度释放对象时,会在控制台上出现如下信息:

2009-03-30 02:30:36.172 ninjaJumper[3997:20b] *** -[GameLayer
retain]: message sent

to deallocated instance 0x59bf670

说明想GameLayer的一个对象发送了retain消息

查看堆栈信息:

如何查看:http://lovebirdegg.javaeye.com/blog/550489

当问题解决后,要将NSZombieEnabled设置为无效,不需要删除变量,将变量前的对号去掉就可以了:

 

设置Global
Breakpoint定位错误代码所在位置

文章分类:移动开发

调式程序的时候经常为了出了错误而不知道原因在哪头疼,可以通过设置XCode的Global Breakpoint快速定位错误代码的位置

步骤一:

Run–>Show–>Breakpoints,进入断点窗口

步骤二:

为-[NSException raise]设置断点

选择Global Breakpoints, 双击Double-click for Symbol, 输入-[NSException
raise],然后按回车。

步骤三:

按照上面的步骤添加objc_exception_throw

以上步骤做完,程序出错的时候就可以定位到问题代码了

当程序出现问题时打开Debugger画面:

点击控制台左边那个按钮,或Run->Debugger会出现如下画面:

在左上角的窗口下出错的方法会加黑,如-[PlayGameViewController gameloop]

单击加黑的方法,程序就回跳转到出错的位置

 

抱歉!评论已关闭.