UINavigationController and memory management

Posted by Dan Ray on Stack Overflow See other posts from Stack Overflow or by Dan Ray
Published on 2010-05-12T14:19:00Z Indexed on 2010/05/12 21:14 UTC
Read the original article Hit count: 325

- (void)launchSearch 
{
 EventsSearchViewController *searchController = [[EventsSearchViewController alloc] initWithNibName:@"EventsSearchView" bundle:nil];
 [self.navigationController pushViewController:searchController animated:YES];
 //[searchController release]; 
}

Notice the [searchController release] is commented out. I've understood that pushing searchController onto the navigation controller retains it, and I should release it from my code. I did just alloc/init it, after all, and if I don't free it, it'll leak.

With that line commented out, navigation works great. With it NOT commented out, I can navigate INTO this view okay, but coming back UP a level crashes with a *** -[CFArray release]: message sent to deallocated instance 0x443a9e0 error.

What's happening here? Is the NavigationController releasing it for me somehow when it goes out of view?

The boilerplate that comes on a UINavigationController template in XCode has the newly-pushed controller getting released. But when I do it, it fails.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about memory-management