0
高德的分配鑑於這個實例變量:iOS版 - 通過屬性
UILabel *label;
及以下屬性:
@property (nonatomic,retain) UILabel *label;
及以下合成:
@synthesize label;
這些是下面的任務正確(關於正確的內存管理):
// 1
UILabel *tmpLabel = [[UILabel alloc] initWithFrame:CGSizeZero];
self.label = tmpLabel;
[tmpLabel release];
// 2
self.label = [[[UILabel alloc] initWithFrame:CGSizeZero] autorelease];
// 3 - This one looks shady but I haven't gotten any leaks (I suppose this will
// not use the created setter)
label = [[UILabel alloc] initWithFrame:CGSizeZero];
- (void)viewDidUnload {
self.label = nil;
[super viewDidUnload];
}
- (void)dealloc {
[label release];
[super dealloc];
}