2

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?

Alex Stone
  • 46,408
  • 55
  • 231
  • 407
  • 2
    Have you tried NSZombieEnabled to YES in your environmental variables ? If not try that first. – ARC Oct 13 '11 at 01:14
  • What Nikita said. You're probably over-releasing an object, and `NSZombie` is designed to detect that. –  Oct 13 '11 at 01:18
  • @Alex Stone code you have showed us looks fine to me. Fixing EXC_BAD_ACCESS is fun. Let us know what happens when you enable NSZombieEnabled. If that doesn't work you can either post your entire sample project ( zip it and share link here ) someone will go through your code – ARC Oct 13 '11 at 01:24

1 Answers1

1

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.

chown
  • 51,908
  • 16
  • 134
  • 170