许多iPhone代码样本(来自苹果等)后,立即释放包括这样的代码:目标C:为什么创建UI对象
- (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];
}
这个片段是从BubbleLevel样本项目。
我的问题:为什么发送消息发送到contentView?我们在self.view中保留对contentView的引用,我们显然希望在应用程序的整个生命周期中使用它,而不仅仅是这种方法。不会调用release会导致视图被释放?
谢谢大家的解释。 – 2009-09-07 15:31:56