views:

490

answers:

1

I seem to be dealloc'ing something like the tab bar itself, navigation controller, or ???, and this happens when I go to a particular view controller and then hit the tab bar to a specific tab (eg, if I hit the middle tab, of 3 tabs, no problem, but if I hit the rightmost tab I get the crash). My program is basically complete and I have a pretty big code base at this point. Anyone have any suggestions for debugging this -- I've been waiting until now to work on this. My sense, is to look at the dealloc routines and any releases in the neighboring code. Any thing less 'manual' you can suggest? Thanks!

+1  A: 

Without knowing more, here's how I would go about it.

  1. In the log viewer, type backtrace after the exception occurs in gdb. Hopefully, this will give you the exact line that shows which object is being free'd too many times.

  2. Look for references to this object and see if you can find the unnecessary release, autorelease, etc. by inspection. You are not to release/autorelease anything that your execution path does not own (via alloc).

You may have some luck printing out retain counts for this object (by sending the retainCount message to the offending object). Though the developer's documentation strongly suggests that this is meaningless and not fruitful, I've found it useful on occasion to help me narrow down when I've freed something by accident.

hyuan
Solved using above debugging:1) Used - (void)viewDidLoad instead of loadView for a nib loaded view controller. 2)Also changed:UIView *contentView = [self.navigationController view];self.view = contentView;[contentView release];to:self.view = [self.navigationController view];
Rob
Sorry for ugly formatting but the site prefers me to leave a comment to an 'already answered question'.
Rob
Your change in point 2 makes sense. Since contentView's UIView was not alloc'd the code path did not own. Therefore, the [contentView release] message was extraneous. Good job!
hyuan
Thanks Hyuan. Someone else (previously 'let go') wrote that line and I was wondering why there was a release with no alloc! Exemplifies your #2: 'see if you can find the unnecessary release' in your suggestion. Thanks for the bread crumbs.
Rob