iPhone 应用程序退出后台时随机崩溃
我有一个 iPhone 应用程序,在极少数情况下,它会在从多任务处理中退出后台时立即崩溃。没有代码正在运行 - 应用程序将在我的 main.m 文件中的这一行立即崩溃:
int retVal = UIApplicationMain(argc, argv, nil, nil);
Xcode 告诉我,“程序收到信号:“EXC_BAD_ACCESS”。
有谁知道为什么会发生这种情况?
I have an iPhone app which on very rare occasion will crash immediately while coming out of background from multitasking. No code is being run - the app will just crash immediately at this line in my main.m file:
int retVal = UIApplicationMain(argc, argv, nil, nil);
Xcode tells me, "Program received signal: "EXC_BAD_ACCESS"."
Does anyone know as to why this would be happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果没有更多信息,很难说这里发生了什么。
当您尝试访问某些无效内存时,会发生 EXC_BAD_ACCESS。这通常是由于过度释放或保留对象不足而发生的。
通过 Cocoa 内存管理指南来刷新您的想法,并查看 CocoaDev
http://www.cocoadev 上的这些页面.com/index.pl?调试技术
http://www.cocoadev.com/index .pl?NSZombieEnabled
您会发现很多技术可以帮助您追踪 EXC_BAD_ACCESS 等内容。
NSZombileEnabled 文章还包含一个非常好的 .gdbinit 文件模板,它将在 GDB 运行时设置大量全局断点并设置一些环境变量。我发现它非常非常有用。
因此,当您设置这些断点并将 NSZombieEnabled 设置为 YES 时,您将不会看到 EXC_BAD_ACCESS,而是会得到一个通常会发生错误访问的断点,以及一条日志消息,内容为“释放发送到已释放的对象”。实例”或类似的东西。这应该能指出你哪里出了问题。
Without any more information it is difficult to say what is happening here.
EXC_BAD_ACCESS happens when you try to access some invalid memory. This usually comes about because of overreleasing or underretaining an object.
Refresh your mind with the Cocoa Memory Management guide and check out these pages on CocoaDev
http://www.cocoadev.com/index.pl?DebuggingTechniques
http://www.cocoadev.com/index.pl?NSZombieEnabled
You'll find a lot of techniques there to help you track down things like EXC_BAD_ACCESS.
The NSZombileEnabled article also contains a pretty good template for a .gdbinit file, which will setup a load of global breakpoints and set some environment variables whenever GDB is run. I find it very very useful.
So when you have these breakpoints in place and NSZombieEnabled set to YES, you won't see EXC_BAD_ACCESS, instead you'll get a breakpoint where the bad access would normally have occurred and a log message along the lines of "release sent to a deallocated instance" or something similar. That should pinpoint where you've gone wrong.
好的。很抱歉浪费了大家的时间,但我做了一些挖掘,发现我错过了一个重要的电话。我忘记在具有 CLLocationManager 的视图控制器中调用以下内容。
感谢您的帮助,贾萨里恩。
Okay. Sorry to have wasted everyone's time, but I did some digging and realised that I was missing an important call. I was forgetting to call the following in my view controller which had a CLLocationManager.
Thanks for your help, Jasarien.