Many iPhone code samples (from Apple, etc.) include code like this:
- (void)viewDidLoad {
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
// add the top-most parent view
UIView *contentView = [[UIView alloc] initWithFrame:applicationFrame];
contentView.backgroundColor = [UIColor blackColor];
self.view = contentView;
[contentView release];
levelView = [[LevelView alloc] initWithFrame:applicationFrame viewController:self];
[self.view addSubview:levelView];
calibrationView = [[CalibrationView alloc] initWithFrame:applicationFrame viewController:self];
}
This snippet is from the BubbleLevel sample project.
My question: why is a release message sent to contentView? We retain a reference to contentView in self.view and we clearly want to use it for the lifetime of the app, not just in this method. Won't calling release cause the view to be released?