Just finished watching the Stanford course lecture on memory management which discusses using Instruments to find leaks. I then ran my Presence assignment with Leaks and got over 300 leaks opening the first tablewView!
Overwhelmed, I decided to rewrite the exercise running with Leaks as I go to see where I was going wrong. I was clean with 0 leaks up until I started adding my first view. This is the DidFinishLaunching method in my AppDelegate and the root view opens without any leaks...
When I add the NavigationController to the view I get my first leak...
When I push my first TableView on to the stack I get another leak.
In PersonListView I am displaying 3 rows with the following code...
In the simulator the 3 rows appear in .05 mins. The 2 leaks appear at .09 mins. The leaked objects are identical "GeneralBlock-128".
Am I doing anything wrong or just not understanding leaks?
Overwhelmed, I decided to rewrite the exercise running with Leaks as I go to see where I was going wrong. I was clean with 0 leaks up until I started adding my first view. This is the DidFinishLaunching method in my AppDelegate and the root view opens without any leaks...
Code:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window makeKeyAndVisible];
}
When I add the NavigationController to the view I get my first leak...
Code:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
}
When I push my first TableView on to the stack I get another leak.
Code:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
PersonListViewController *personListViewController =[[[PersonListViewController alloc]
initWithNibName:@"PersonListViewController" bundle:nil] autorelease];
[self.navigationController pushViewController:personListViewController animated:NO];
[personListViewController release];
}
In PersonListView I am displaying 3 rows with the following code...
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
cell.textLabel.text = @"A Cell";
return cell;
}
In the simulator the 3 rows appear in .05 mins. The 2 leaks appear at .09 mins. The leaked objects are identical "GeneralBlock-128".
Am I doing anything wrong or just not understanding leaks?