memory management - iOS - assignment of ivars through properties -
given instance variable:
uilabel *label;
and below property:
@property (nonatomic,retain) uilabel *label;
and following synthesize:
@synthesize label;
are these below assignments correct (with respect correct memory management):
// 1 uilabel *tmplabel = [[uilabel alloc] initwithframe:cgsizezero]; self.label = tmplabel; [tmplabel release]; // 2 self.label = [[[uilabel alloc] initwithframe:cgsizezero] autorelease]; // 3 - 1 looks shady haven't gotten leaks ( suppose // not use created setter) label = [[uilabel alloc] initwithframe:cgsizezero]; - (void)viewdidunload { self.label = nil; [super viewdidunload]; } - (void)dealloc { [label release]; [super dealloc]; }
all correct. thing note if release label in -viewdidunload have recreate in viewwillload. correct in number 3 not go through setter.
Comments
Post a Comment