当将应用程序部署到设备时,程序将在几个周期后退出,并出现以下错误:

Program received signal: "EXC_BAD_ACCESS".

程序在iPhone模拟器上运行没有任何问题,只要我一次执行一个指令,它也会调试和运行。一旦我让它再次运行,我将击中EXC_BAD_ACCESS信号。

在这种特殊情况下,它恰好是加速度计代码中的一个错误。它不会在模拟器中执行,这就是它不会抛出任何错误的原因。但是,它将在部署到设备后执行。

这个问题的大多数答案都处理一般的EXC_BAD_ACCESS错误,因此我将保留这个选项,作为可怕的坏访问错误的统称。

EXC_BAD_ACCESS通常是非法内存访问的结果。你可以在下面的答案中找到更多信息。

您以前遇到过EXC_BAD_ACCESS信号吗?您是如何处理它的?


当前回答

根据我的经验,这通常是由非法内存访问引起的。检查所有指针,特别是对象指针,以确保它们已初始化。确保你的主窗口。Xib文件(如果您正在使用的话)已正确设置,并具有所有必要的连接。

If none of that on-paper checking turns anything up, and it doesn't happen when single-stepping, try to locate the error with NSLog() statements: sprinkle your code with them, moving them around until you isolate the line that's causing the error. Then set a breakpoint on that line and run your program. When you hit the breakpoint, examine all the variables, and the objects in them, to see if anything doesn't look like you expect.I'd especially keep an eye out for variables whose object class is something you didn't expect. If a variable is supposed to contain a UIWindow but it has an NSNotification in it instead, the same underlying code error could be manifesting itself in a different way when the debugger isn't in operation.

其他回答

这是一个很好的帖子。以下是我的经验:我在属性声明中搞砸了retain/assign关键字。我说:

@property (nonatomic, assign) IBOutlet UISegmentedControl *choicesControl;
@property (nonatomic, assign) IBOutlet UISwitch *africaSwitch;
@property (nonatomic, assign) IBOutlet UISwitch *asiaSwitch;

我该说什么来着

@property (nonatomic, retain) IBOutlet UISegmentedControl *choicesControl;
@property (nonatomic, retain) IBOutlet UISwitch *africaSwitch;
@property (nonatomic, retain) IBOutlet UISwitch *asiaSwitch;

我只是遇到了这个问题。对我来说,原因是删除一个CoreData管理对象,然后试图从另一个地方读取它。

EXC_BAD_ACCESS

EXC_BAD_ACCESS访问已经释放的对象。内核发送这个异常(EXC),表示内存块不能被访问(BAD ACCESS)。

使用[无主(不安全)] 当一个目标器使用另一个目标器时,IPHONEOS_DEPLOYMENT_TARGET[About]。在我的例子中,Test target(10.0)使用了显式依赖[About]与14.0 IPHONEOS_DEPLOYMENT_TARGET

我知道之前有人问过这个问题,但是在读了这个帖子之后,我找到了XCode 4.2的解决方案: Product -> Edit Scheme -> Diagnostics Tab ->启用僵尸对象

帮助我找到一个消息被发送到一个释放对象。

运行应用程序,在它失败后(应该显示“中断”而不是“EXC_BAD_ACCESS”…检查控制台(Run > Console)…现在应该有一条消息告诉它要访问什么对象。