解除分配后,iPhone4 UIView 的 EXC_BAD_ACCESS。如何调试?

发布于 2024-12-09 07:27:40 字数 1473 浏览 1 评论 0原文

我正在使用苹果的加速计图表示例: http://developer.apple.com/library/ios/ #samplecode/AccelerometerGraph/Introduction/Intro.html

我将 2 个图形视图推送到导航控制器上:

  GraphViewController* graphViewController = [[GraphViewController alloc]initWithNibName:@"GraphViewController" bundle:nil];

    [self.navigationController pushViewController:graphViewController animated:YES];
    [graphViewController release];

图形由外部方法更新:

     [motionManager startDeviceMotionUpdatesToQueue:motionQueue withHandler:^(CMDeviceMotion *motion, NSError *error) {
...

      if(graphDelegate)
                    {
                        [self performSelectorInBackground:@selector(notifyGraphDelegateWithMotionEvent:) withObject:motion];

                    }

}

,该方法调用

 [unfiltered addX:filteredValue y:unfilteredvalue z:10]; 

每个图形。更新频率为每秒 20 次

当我从导航控制器弹出视图时,我在 [super dealloc] 之后收到 EXC_BAD_ACCESS

-(void)dealloc
{
    // Since 'text' and 'current' are weak references, we do not release them here.
    // [super dealloc] will take care to release 'text' as a subview, and releasing 'segments' will release 'current'.
    [segments release];
    [super dealloc];
}

这是一个令人讨厌的错误,我真的不知道如何解决类似的问题。这似乎与视图取消分配的顺序有关,因为崩溃发生在视图弹出之后。关于如何解决类似问题有什么想法吗?

I'm working with Apple's Accelerometer Graph Example:
http://developer.apple.com/library/ios/#samplecode/AccelerometerGraph/Introduction/Intro.html

I'm pushing 2 Graph Views onto a navigation controller:

  GraphViewController* graphViewController = [[GraphViewController alloc]initWithNibName:@"GraphViewController" bundle:nil];

    [self.navigationController pushViewController:graphViewController animated:YES];
    [graphViewController release];

The graph's are updated by an external method:

     [motionManager startDeviceMotionUpdatesToQueue:motionQueue withHandler:^(CMDeviceMotion *motion, NSError *error) {
...

      if(graphDelegate)
                    {
                        [self performSelectorInBackground:@selector(notifyGraphDelegateWithMotionEvent:) withObject:motion];

                    }

}

, which calls

 [unfiltered addX:filteredValue y:unfilteredvalue z:10]; 

for each graph. The frequency of updates is 20 times per second

When I pop the view from the navigation controller, I get EXC_BAD_ACCESS after [super dealloc]

-(void)dealloc
{
    // Since 'text' and 'current' are weak references, we do not release them here.
    // [super dealloc] will take care to release 'text' as a subview, and releasing 'segments' will release 'current'.
    [segments release];
    [super dealloc];
}

This is a nasty error, and I really don't know how to troubleshoot something like that. It seems to be something about the order in which the views are de-allocated, as the crash happens after the view is popped. Any ideas on how to troubleshoot something like that?

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

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

发布评论

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

评论(1

十雾 2024-12-16 07:27:40

设置 NSZombieEnabledMallocStackLogging在调试器中保护 malloc。然后,当您的应用程序崩溃时,在 gdb 控制台中输入以下内容:

(gdb) info malloc-history 0x543216

将 0x543216 替换为导致崩溃的对象的地址,您将获得更有用的堆栈跟踪,它应该可以帮助您查明位置代码中导致问题的确切行。

请参阅本文以获取更详细的说明。

Set NSZombieEnabled, MallocStackLogging, and guard malloc in the debugger. Then, when your App crashes, type this in the gdb console:

(gdb) info malloc-history 0x543216

Replace 0x543216 with the address of the object that caused the crash, and you will get a much more useful stack trace and it should help you pinpoint the exact line in your code that is causing the problem.

See this article for more detailed instructions.

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