I have a parent table view controller with a readonly detail view controller property on it that lazily instantiates a detail view controller. If I am on an iphone/ipod, I configure and push the detail view controller when an item in the table gets selected. When the detail view is visible and I click back twice in the navigation controller, the detail controller then the parent controller get popped and the parent’s dealloc gets called. When the parent’s dealloc reaches the line where I call [detailViewController release], I get a crash with EXC_BAD_ACCESS from the navigation controller. That makes me think that my problem is with memory management of the detailViewController, but debugging with NSZombies shows no problems. (Commenting out the [detailViewController release] line makes the crash go away but then I never have a release to balance out the detailViewController’s alloc — memorey leak) Any ideas why I get this crash?
EDIT:
here’s a stack trace for the crash:
Program received signal: “EXC_BAD_ACCESS”.
(gdb) bt
#0 0x01046a63 in objc_msgSend ()
#1 0x0a9d72a0 in ?? ()
#2 0x0000cb4c in -[MyTableViewController dealloc] (self=0xa956840, _cmd=0x127a9d6) at /Users/nick/Documents/MyApp/Classes/MyTableViewController.m:290
#3 0x00390f1d in -[UINavigationController setDisappearingViewController:] ()
#4 0x0038e4f6 in -[UINavigationController _clearLastOperation] ()
#5 0x0038ee3f in -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] ()
#6 0x0051be23 in -[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:] ()
#7 0x0051cfd2 in -[UINavigationTransitionView _cleanupTransition] ()
#8 0x00308665 in -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] ()
#9 0x003084f7 in -[UIViewAnimationState animationDidStop:finished:] ()
#10 0x0200c6cb in run_animation_callbacks ()
#11 0x0200c589 in CA::timer_callback ()
#12 0x01225fe3 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ ()
#13 0x01227594 in __CFRunLoopDoTimer ()
#14 0x01183cc9 in __CFRunLoopRun ()
#15 0x01183240 in CFRunLoopRunSpecific ()
#16 0x01183161 in CFRunLoopRunInMode ()
#17 0x01a5a268 in GSEventRunModal ()
#18 0x01a5a32d in GSEventRun ()
#19 0x002e642e in UIApplicationMain ()
#20 0x00001b28 in main (argc=1, argv=0xbffff070) at /Users/nick/Documents/MyApp/main.m:14
EDIT2:
dealloc method where the crash happens:
- (void)dealloc
{
[context release]; // a managed object context -- when table entries are selected, they get cached in core data
[tableDataArray release];
[detailViewController release]; // <-- line 290, this is where it crashes
[super dealloc];
}
You’ve either:
A) Forgotten to retain the object stored to your
detailViewControllerivaror
B) Released the object stored to your
detailViewControllerivar too many timesThus when you attempt to release
detailViewControllerin your-deallocmethod, it’s already been deallocated and points to invalid memory. You should audit the places where you set the value ofdetailViewControllerin this class for one of these situations. If you aren’t seeing it, add the code where you manipulate that ivar to your question so we can examine it.