objective c - releasing UIViewController subclasses does not actually free up memory -


i have uinavigationcontroller object (named loginnav) consists of viewcontroller1 & viewcontroller2, ipad app starts loading uisplitviewcontroller subclass (named mainsplitviewcontroller) , presenting loginnav modally on top of (this way done in didfinishlaunchingwithoptions method of appdelegate this:

[self.mainsplitviewcontroller presentmodalviewcontroller:loginnav animated:yes];).

once viewcontroller1 shown, tap uibutton in push viewcontroller2, when finish working in viewcontroller2 tap uibutton in call [self.navigationcontroller dismissmodalviewcontrolleranimated:yes]; dismiss loginnav both of view controllers , show mainsplitviewcontroller's contents.

there dealloc method in both viewcontroller1 & viewcontroller2 nslog statement in each one, once loginnav dismissed, nslogs never fired, doing [self.navigationcontroller.viewcontrollers objectatindex:0] release]; & [self.navigationcontroller.viewcontrollers objectatindex:1] release]; right after [self.navigationcontroller dismissmodalviewcontrolleranimated:yes]; fires both nslogs.

i commented out above 2 release statements, launched allocations instrument, , launched app again , pushed viewcontroller2 dismissed loginnav described above, , looked @ live bytes column (all allocations value ) 6.9 mb right after dismissal of loginnav, did step again in case using 2 release statements, got 6.9 mb value on live bytes column.

two questions:

1) why not dealloc methods of viewcontroller1 & viewcontroller2 never fired after dismissal of navigation controller loginnav holds them ? , correct above 2 release statements release these view controllers ?

2) why releasing viewcontroller1 & viewcontroller2 not free memory ?

p.s. there no single variable (or iboutlet) being held in memory in both viewcontroller1 & viewcontroller2, released in both of them.

these kinds of issues impossible troubleshoot without seeing code. when manage memory manually, there multiple areas can go wrong. example following code leak:

- (void)didselectsomethinginviewcontrollerone {     viewcontroller2 *vc2 = [[viewcontroller2 alloc] init];     [self.navigationcontroller pushviewcontroller:vc2 animated:yes]; } 

in case have allocated object , have ownership of it. nav controller takes ownership of it. when pop controller navigation stack, navigation controller relinquishes ownership of it, never did, still has retain count of 1 , won't deallocated.

relinquishing ownership of controllers later in code (like after dismissing modal view) bad idea. makes difficult analyze ownership when releases on place. navigation controller has ownership can release object allocated, not intend use in future:

- (void)didselectsomethinginviewcontrollerone {     viewcontroller2 *vc2 = [[viewcontroller2 alloc] init];     [self.navigationcontroller pushviewcontroller:vc2 animated:yes];     [vc2 release]; } 

the situation above can have nothing problem. problem may reside in many different areas. why troubleshooting memory management problems difficult. without seeing source code.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -