dealloc之后的UIView的iPhone4 EXC_BAD_ACCESS。怎么调试?

时间:2011-10-13 01:10:16

标签: exception uiview ios4 uinavigationcontroller iphone-4

我正在使用Apple的Accelerometer Graph示例: 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];
}

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

1 个答案:

答案 0 :(得分:1)

在调试器中设置NSZombieEnabledMallocStackLoggingguard malloc。然后,当您的应用程序崩溃时,请在gdb控制台中输入:

(gdb) info malloc-history 0x543216

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

See this article for more detailed instructions.