iphone - Memory not releasing after popToRootViewControllerAnimated -


i using navigationcontroller in app. after push , pop view controller 3 times app crashes because of low memory. code below.

- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {         self.window = [[uiwindow alloc] initwithframe:[[uiscreen mainscreen] bounds]];         homepagevc *homepage = [[viewcontroller alloc] homepage = [[viewcontroller alloc] initwithnibname:@"mainview-ipad" bundle:nil];         navigationcontroller = [[uinavigationcontroller alloc] initwithrootviewcontroller:homepage];         self.window.rootviewcontroller = navigationcontroller;         [self.window makekeyandvisible];         return yes; } 

when user pushes button, send him view controller.

 -(ibaction)showmap:(id)sender  {     mapviewcontroller *mapviewcontroller = nil;     mapviewcontroller = [[mapviewcontroller alloc] initwithnibname:@"mapview-ipad" bundle:nil];     appdelegate *appdelegate = (appdelegate *)[[uiapplication sharedapplication] delegate];     [appdelegate.navigationcontroller pushviewcontroller:mapviewcontroller animated:yes];  } 

when want come rootview controller, do

-(ibaction)goback:(id)sender {     appdelegate *appdelegate = (appdelegate *)[[uiapplication sharedapplication] delegate];     [appdelegate.navigationcontroller poptorootviewcontrolleranimated:yes]; } 

now after doing few times, gradually didreceivelowmemory gets called , app crashes.

to debug more, printed memory usage in loop.

-(void) report_memory {     struct task_basic_info info;     mach_msg_type_number_t sizem = sizeof(info);     kern_return_t kerr = task_info(mach_task_self(),                                task_basic_info,                                (task_info_t)&info,                                &sizem);     if( kerr == kern_success ) {         nslog(@"memory usage: %.4lf mb", info.resident_size/1000000.0);     } else {         nslog(@"error task_info(): %s", mach_error_string(kerr));     } } 

the outputs are

when app launches    : memory usage: 137.8263 mb after showmap first time : memory usage: 206.2172 mb gone home           : memory usage: 223.6580 mb   ==> mapvc didn't release  after showmap second time: memory usage: 227.2172 mb press go home       : memory usage: 250.2172 mb   ==> mapvc didn't release  after showmap third time : app crashes 

my lowmemory written as

- (void)didreceivememorywarning {     [super didreceivememorywarning];     nslog(@"got low memory %@",[self class]); } 

to add more surprise got low memory warning both homepagevc , mapvc. if have alreay pooped out mapvc how did receive lowmemory ? , why memory consumed mapvc did not released ? using arc.

i having same problem in code (using arc) uiviewcontroller not being released after call poptorootviewcontrolleranimated:

the reason error due nstimer in uiviewcontroller. trying invalidate timer in dealloc because nstimer using target:self (i.e. retaining pointer uiviewcontroller) dealloc never being called.

to fix issue, invalidated timer in viewwilldisappear.


Comments

Popular posts from this blog

Need help in packaging app using TideSDK on Windows -

java - Why does my date parsing return a weird date? -

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -