2011-03-29 55 views
0
UILabel *labelTitle = [[UILabel alloc] initWithFrame:CGRectMake(90, 80, 80, 50)]; 
[self.view addSubView:labelTitle]; 
[labelTitle release]; 

我可以释放对象以这种方式

UILabel *labelTitle = [[[UILabel alloc] initWithFrame:CGRectMake(90, 80, 80, 50)] autorelease]; 
[self.view addSubView:labelTitle]; 

谢谢!

+0

第一种方法更清洁,更易于管理。 – Mark 2011-03-29 07:06:13

回答

0

这是第一种方式。第二个基本上将发布延迟到稍后的时间。这往往会在某些情况下使用更多资源,因为未使用的内存不会尽快返回。


其实使用allocWithZone:NULL代替alloc保存方法调用。

相关问题