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
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: