Tutorial :UINavigationController crashes due to a NSArray variable



Question:

I push a view controller into current navigation controller. It works fine, except when I am getting out of the current view controller, it crashes.

MyTableView *newPage = [[MyTableView alloc] initWithNibName:@"table2" bundle:nil];  [[self navigationController] pushViewController:newPage animated:YES];  //[newPage release];  

I comment out the last line to prevent crash. I read another post about variables being over released. In the newPage, I only have one variable (arrCellText), and is initialized in the initWithNibName

NSArray *temp = [[NSArray alloc] initWithObjects:@"string1", @"string2", @"string3", nil];  [self setArrCellText: temp];  [temp release];  

I put the release in the dealloc

[arrCellText release];  

If I comment out setting and release of arrCellText, it works fine too. I must not have complete understanding of memory management, and I would like to understand this better. TIA


Solution:1

Where does the crash happen exactly? First you can release 'newPage' after pushing it onto the navigationController (because it's retained there).

You might try to access anything from newPage after coming back. 'newPage' was released in the mean time and thus has some garbage value (but not nil).


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »