Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS memory leak, custom TabBar runaway allocation of view controllers
    text
    copied!<p>I am using the following code to switch between two tabs:</p> <pre><code>-(void)switchPage:(UIButton *)sender{ DLog(@""); DLog(@"child view controllers %lu", (unsigned long)self.childViewControllers.count); switch(sender.tag){ case 0:{ for(id object in self.childViewControllers){ if([object isKindOfClass:[QuestionsVC class]]){ [questionsTab willMoveToParentViewController:nil]; [questionsTab.view removeFromSuperview]; [questionsTab removeFromParentViewController]; questionsTab = nil; } } questionsTab = [[QuestionsVC alloc] init]; [self addChildViewController:questionsTab]; [self.view addSubview: questionsTab.view]; [questionsTab didMoveToParentViewController:self]; [self.view bringSubviewToFront:tabBarView]; [self drawGrayLineLayer]; break; } case 1:{ for(id object in self.childViewControllers){ if([object isKindOfClass:[AnswersVC class]]){ [answersTab willMoveToParentViewController:nil]; [answersTab.view removeFromSuperview]; [answersTab removeFromParentViewController]; answersTab = nil; } } answersTab = [[AnswersVC alloc] init]; [self addChildViewController:answersTab]; [self.view addSubview: answersTab.view]; [answersTab didMoveToParentViewController:self]; [self.view bringSubviewToFront:tabBarView]; [self drawGrayLineLayer]; break; } } </code></pre> <p>The curious thing is that the count of childVCs for the root viewcontroller (the tab bar), remains constant while none of the childviewcontrollers are released. </p> <p>What is the problem?</p> <p>Below is an instruments snapshot telling me that each viewcontroller gets re-allocated each time the code runs, and the old one does not get deallocated. </p> <p><img src="https://i.stack.imgur.com/M13Gj.png" alt="enter image description here"> <img src="https://i.stack.imgur.com/jRAK0.png" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload