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

Program received signal: "EXC_BAD_ACCESS".

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

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

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

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

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


当前回答

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

其他回答

XCode 4及以上版本,它已经通过Instruments变得非常简单了。在仪器中运行僵尸。本教程很好地解释了它:调试exc_bad_access错误xcode工具

我只是在试图执行一个包含大数组的C方法时,才在iPhone上遇到了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.

在过去的四个小时里,我一直在调试和重构代码来解决这个错误。上面的一篇文章让我发现了这个问题:

属性: startPoint = [[DataPoint alloc] init]; startPoint= [DataPointList objectAtIndex: 0]; . . . x = startPoint。X - 10;/ / EXC_BAD_ACCESS

房地产后: startPoint = [[DataPoint alloc] init]; startPoint = [[DataPointList objectAtIndex: 0] retain];

再见EXC_BAD_ACCESS

再补充一种可能发生这种情况的情况:

我有密码:

NSMutableString *string;
[string   appendWithFormat:@"foo"];

显然,我忘记了为字符串分配内存:

NSMutableString *string = [[NSMutableString alloc] init];
[string   appendWithFormat:@"foo"];

解决问题。