memory management - Retain vs Assign for controls inside NIB/XIB using the iPhone SDK -
i'm using interface builder build rootviewcontroller, retained application delegate. have few controls in xib such couple uibuttons, uislider, etc. iboutlets, hooked in interface builder.
on code implementation side of xib, i've seen people use:
@interface rootviewcontroller : uiviewcontroller { iboutlet uibutton *button1; iboutlet uibutton *button2; ... } @property(nonatomic, assign) uibutton *button1; @property(nonatomic, assign) uibutton *button2; @end
why use assign instead of retain? i've seen people not use assign property.
is pointless use retain since rootviewcontroller's xib contain reference them long loaded? or being lazy , not going through steps retain, synthesize & dealloc? seems me can't hurt keep reference around long control needed , viewcontroller hasn't been dealloc'ed, wondering if xib's differently wouldn't necessary.
i've read memory management guide, btw.
thanks!
it cant hurt keep subviews assigned instead of retained long stay child there superview.
when remove superview , want add subview later on in code. thats not possible. when remove super retain count turn zero. thats 1 of reasons why use retain. controller object owner of view object.
i cant think of other reasons must use retain instead of assign.
i use retain, think best practice outlets , seems convention.
Comments
Post a Comment