I'm using a UINavigationController and I'm having trouble releasing objects when I push a new view. I want to set an object on the new controller before pushing it. The way I'm currently doing this is:
OpenPageViewController *varOpenPageController = [[OpenPageViewController alloc] initWithNibName:@"OpenPageViewController" bundle:nil];
varOpenPageController.bookObj = bookObj;
[[self navigationController] pushViewController:varOpenPageController animated:YES];
//[varOpenPageController release];
If I uncomment that last line then the program crashes when I navigate back throughout my controller. I also have another question regarding when/how to release an object. In the bookObj I have a mutable array of Page objects and I want to change the text of the current page object. I do this by:
Page *pageObj = [[bookObj pagesArray] objectAtIndex:currentPage];
pageObj.page_Text = textView.text;
[[bookObj pagesArray] replaceObjectAtIndex:currentPage withObject:pageObj];
//[pageObj release];
The program crashes if I uncomment that last line as well. It will let me navigate forward but when I navigate back and try to go forward again it crashes.
Autoreleasing the objects bring similar results. Please advise if you can. Thanks.
EDIT: When I do release the first example varOpenPageController and run the simulator with Leaks then the program seems to function properly. However, if I don't run Leaks then it crashes. Does anyone have any ideas why this might happen? Thanks.