Reputation: 5929
I'm just learning how to code for the iPhone using Objective-C, and I don't quite understand why a view controller needs to be released when its in use?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
Thanks in advance
Upvotes: 1
Views: 90
Reputation: 9080
The dl;dr of what I have below is this: take care of your local memory management, don't worry about needing to manage the memory of API classes. They manage their own memory.
Some things to remember with Objective-C memory management:
If you use properties that are objects with dot notation and the property is a copy or retain property (usually what you want), don't do this:
self.property = [[WhateverObject alloc] init];
instead, do this:
self.property = [[[WhateverObject alloc] init] autorelease;
Upvotes: 1
Reputation: 14414
The navigation controller retained the detail view controller already, therefore, the retain count is 2 at that point. The release will make the retain count 1.
Upvotes: 3