iphone - Do I need to release xib resources? -


if have uilabel linked xib file, need release on dealloc of view? reason ask because don't alloc it, makes me think don't need release either? eg (in header):

iboutlet uilabel *lblexample; 

in implementation:

.... [lblexample settext:@"whatever"]; ....  -(void)dealloc{     [lblexample release];//????????? } 

if follow considered best practice, should release outlet properties, because should have retained them in set accessor:

@interface mycontroller : mysuperclass {     control *uielement; } @property (nonatomic, retain) iboutlet control *uielement; @end   @implementation mycontroller  @synthesize uielement;  - (void)dealloc {     [uielement release];     [super dealloc]; } @end 

the advantage of approach makes memory management semantics explicit , clear, and works consistently across platforms nib files.

note: following comments apply ios prior 3.0. 3.0 , later, should instead nil out property values in viewdidunload.

one consideration here, though, when controller might dispose of user interface , reload dynamically on demand (for example, if have view controller loads view nib file, on request -- under memory pressure -- releases it, expectation can reloaded if view needed again). in situation, want make sure when main view disposed of relinquish ownership of other outlets can deallocated. uiviewcontroller, can deal issue overriding setview: follows:

- (void)setview:(uiview *)newview {     if (newview == nil) {         self.uielement = nil;     }     [super setview:aview]; } 

unfortunately gives rise further issue. because uiviewcontroller implements dealloc method using setview: accessor method (rather releasing variable directly), self.anoutlet = nil called in dealloc in response memory warning... lead crash in dealloc.

the remedy ensure outlet variables set nil in dealloc:

- (void)dealloc {     // release outlets , set variables nil     [anoutlet release], anoutlet = nil;     [super dealloc]; } 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -