iphone - What happens to the views added via interface builder when memory warning is low? -
when low memory warning, release views, set outlets nil, , recreate them on again. views added in interface builder, added when initwithnibname called.
so, in general bad practice use lot of views via interface builder or automatically taken care of original uiviewcontroller
implementation of didreceivememorywarning(ios 6+) or viewdidunload (ios 5 , below)
?
the default behavior viewcontroller
load view hierarchy when view property first accessed , thereafter keep in memory until view controller disposed of. there no indication view created using code different 1 created in interface builder. prefer interfacebuilder owing app maintenance since ui code gets complex pretty fast , separating ui elements functional aspect of ui elements clean bifurcation making easy new programmer maintain code base.
but when comes releasing memory didreceivememorywarning
delegate used explicitly release view hierarchy if additional memory necessary app.
- (void)didreceivememorywarning { [super didreceivememorywarning]; // add code clean of own resources no longer necessary. if ([self.view window] == nil) { // add code preserve data stored in views might // needed later. // add code clean other strong references view in // view hierarchy. self.view = nil; } return; }
note here test if view controller’s view not onscreen. if view associated window, cleans of view controller’s strong references view , subviews. if views stored data needs recreated, implementation of method should save data before releasing of references views. storing either can keep in memory part of previous viewcontroller's memory or store in coredate or other persistent (disk cache etc) way.
the next time view property accessed, view reloaded first time. pictographically makes perfect sense -
Comments
Post a Comment