iPhone 应用程序退出后台时随机崩溃

发布于 2024-10-18 15:01:30 字数 236 浏览 4 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月流歌 2024-10-25 15:01:30

如果没有更多信息,很难说这里发生了什么。

当您尝试访问某些无效内存时,会发生 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.

逆光下的微笑 2024-10-25 15:01:30

好的。很抱歉浪费了大家的时间,但我做了一些挖掘,发现我错过了一个重要的电话。我忘记在具有 CLLocationManager 的视图控制器中调用以下内容。

- (void)dealloc 
{
    myLocationManager.delegate = nil;
    [myLocationManager release];

    [super dealloc];
}

感谢您的帮助,贾萨里恩。

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.

- (void)dealloc 
{
    myLocationManager.delegate = nil;
    [myLocationManager release];

    [super dealloc];
}

Thanks for your help, Jasarien.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文