views:

31

answers:

1

Running Instruments on my iPad app found 2 leaks, except I cannot understand where they are coming from. The first one is in this method in my app delegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    [window addSubview:self.viewController.view]; // <--- it leaks on this line
    [window makeKeyAndVisible];
    return YES;
}

I don't know why this is leaking, I am releasing viewController in dealloc. The second leak is in one of my table view controllers in this section of code:

EditLocationViewController *locationController = [[EditLocationViewController alloc] initWithLocation:self.location];
        [self.navigationController pushViewController:locationController animated:YES]; // <--- it leaks on this line
        [locationController release];

I went through my EditLocationViewController class and made sure that all retained properties are being released, etc. so I can't see a reason why it would leak.

Either I'm missing something here or Instruments is reporting false positives.

A: 

What makes you think it leaks there? My guess is the view itself is being leaked in both cases (the one belonging to the controller that you're making visible), or one of the ancillary views that's loaded as part of the view controller's -loadView or -viewDidLoad (this includes views loaded from a nib and attached to an outlet in the view controller).

If you're using the IBOutlet declaration on your ivars, this could very well be the case, as those ivars will be retained by the view controller. In that case you need to release them in -viewDidUnload as well as in -dealloc (be sure to nil them out after releasing them in -viewDidUnload or you'll crash the next time you access them).

Kevin Ballard