when I try to release a dictionary I get an exception.
Here is my code:
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if (!tableDataDictionary) { DebugLog(@'initializing tableDataDictionary'); tableDataDictionary = [ [NSMutableDictionary alloc] init]; } } -(void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [mainTableView deselectRowAtIndexPath: [mainTableView indexPathForSelectedRow] animated:NO]; [tableDataDictionary release]; }
How can I fix it?
Most likely you need to nil out the tableDataDictionary instance variable. Otherwise, the first time each of these methods run, it will work fine, but the second time, tableDataDictionary will not be nil, and will be pointing at a dealloc’d pointer; thus the alloc call will not be made, and when viewWillDisappear: is called, it will try to dealloc that pointer again. So, to fix it:
-(void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [mainTableView deselectRowAtIndexPath: [mainTableView indexPathForSelectedRow] animated:NO];}