核心数据应用程序崩溃,“EXC_BAD_ACCESS” & NS僵尸

发布于 2024-11-08 13:22:12 字数 815 浏览 0 评论 0原文

我目前正在开发一个严重依赖核心数据的应用程序。我 使用导航控制器来推送和弹出视图。当我走的时候 有时程序会回到导航控制器的堆栈中 崩溃,我收到错误(通常在 ManagedObjectContext 合成或释放):

"Thread 1: Program received signal: "EXC_BAD_ACCESS".

我使用静态分析器修复了它发现的所有泄漏。

我使用了 NSZombie,看起来我的分配量增加了,但当我关闭菜单视图时,分配量却没有减少。然后,当我单击另一个菜单视图时,我得到两个结果。

0 Category:NSManagedObjectContext EventType:Malloc RefCt:1 Timestamp:00:04.133.722 Address:0x5da0f10 Size:128 RespLib:pua-app RespCaller:-[pua_appAppDelegate managedObjectContext]

1 Category:NSManagedObjectContext EventType:Zombie RefCt:-1 Timestamp:00:16.524.983 Address:0x5da0f10 Size:0 RespLib:pua-app RespCaller:-[OpenersroutinesMenuViewController setManagedObjectContext]

我对此类调试的经验为零,但显然托管对象上下文“不高兴”,我的猜测是我在通过菜单传递上下文时没有正确创建或管理上下文。这也很有趣,因为 MOC 在这些菜单中没有被更改,并且在修改它的视图中不会发生此错误。

I am currently working on an app that heavily relies on Core Data. I
use a navigation controller to push and pop views around. When I go
back in the stack in the navigation controller the program sometimes
crashes and I receive the error (usually highlighted on a
managedObjectContext synthesize or dealloc):

"Thread 1: Program received signal: "EXC_BAD_ACCESS".

I used the static analyzer to fix all the leaks it found.

I used NSZombie and it seems like my allocations go up, and then do not go down as I pull the menu views off. Then when I click on another menu view I get two results.

0 Category:NSManagedObjectContext EventType:Malloc RefCt:1 Timestamp:00:04.133.722 Address:0x5da0f10 Size:128 RespLib:pua-app RespCaller:-[pua_appAppDelegate managedObjectContext]

1 Category:NSManagedObjectContext EventType:Zombie RefCt:-1 Timestamp:00:16.524.983 Address:0x5da0f10 Size:0 RespLib:pua-app RespCaller:-[OpenersroutinesMenuViewController setManagedObjectContext]

I have ZERO experience with this type of debugging, but apparently the managed object context is 'unhappy' and my guess is that I am not properly creating or managing the context as it is passed through the menu. This is also interesting because the MOC is not being altered in these menus, and in the views where it is modified this error does not occur.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

橘亓 2024-11-15 13:22:12

首先,泄漏永远不会导致这种崩溃。泄漏是指释放不足。这些崩溃通常是由于过度释放造成的。

从您的 NSZombie 输出来看,您的 MOC 似乎被过度释放了。我会查看处理 ManagedObjectContext 的每个位置,并确保正确保留和释放它。第一条规则是使用访问器,而不是直接弄乱您的 ivars(除了 -init-dealloc 和您的访问器,它们应该使用 ivars)。

造成此类问题的一个可能原因是多线程。确保您没有从多个线程访问同一个 MOC。它们不是线程安全的。

该问题可能与视图或菜单无关。问题很可能是您在未保留的 MOC 上调用 -release

First, leaks will never cause this kind of crash. A leak is an under-release. These crashes are generally cause by an over-release.

From your NSZombie output, it looks like your MOC is the thing being over-released. I would look at each place you handle a managedObjectContext and make sure that you retain and release it correctly. The first rule is to use accessors rather than messing with your ivars directly (except in -init, -dealloc and your accessors, which should use the ivars).

A possible cause of this kind of issue is multi-threading. Make sure that you're not accessing the same MOC from multiple threads. They're not thread-safe.

The issue probably has nothing to do with the views or the menus. The problem is most likely that you're calling -release on a MOC that you did not retain.

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