I'm trying to have a custom UIViewController class get popped to the navigation controller, and then when that popped controller is no longer being viewed, have it be deallocated. However, the view controller is sticking around and I'm not sure why. Any help would be appreciated.
Interface:
@property (nonatomic, retain) CustomViewController *viewcontroller;
Implementation:
CustomViewController *vc = [[CustomViewController alloc] initWithNibName:@"CustomViewController" bundle:nil];
self.CustomViewController = vc;
[vc release]; // Release this after setting property to avoid memory leak.
[[self navigationController] pushViewController:[self.CustomViewController autorelease] animated:YES];
// Push in the next view. My thinking is that since pushViewController retains this view, if I autorelease when I send the view, the only thing still retaining the view when it shows up will be the navigation controller, and thus when it is bounced back off of the navigation stack, it should be deallocated. But apparently that's not happening..
Your alloc and init give it a retain count of 1, going throught the CustomViewController property gives it a retain message again, taking it to 2.
You need to do the following, at some point to release....
self.CustomViewController = nil;
Although I am not sure why you are event storing a reference to it...?!