8

When the user clicks a button it presents a new tab bar view controller with two view controllers. Here's how I do that

ACLevelDownloadController *dvc = [[ACLevelDownloadController alloc] initWithNibName:@"ACLevelDownloadController" bundle:[NSBundle mainBundle]];
ACInstalledLevelsController *ivc = [[ACInstalledLevelsController alloc] initWithNibName:@"ACInstalledLevelsController" bundle:[NSBundle mainBundle]];
UITabBarController *control = [[UITabBarController alloc] init];
control.viewControllers = @[dvc, ivc];
dvc.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:0];
ivc.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:1];
[self presentViewController:control animated:YES completion:nil];

this works fine. I dismiss that view controller with a dismiss method in both the ACLevelDownloadController and ACInstalledLevelsController. That also works fine. What's strange is that the memory usage goes up when I present the view controller enter image description here

but it never goes back down. If I present it again, it goes up even more enter image description here I'm using ARC. Why is the memory that the view controllers use not being released after they are dismissed?

EDIT

The way they are dismissed is both ACLevelDownloadController and ACInstalledLevelsController have IBActions hooked up that call this method when they are clicked

- (void)dismiss:(id)sender{
    [self dismissViewControllerAnimated:YES completion:nil];
}
Community
  • 1
  • 1
Chris Loonam
  • 5,735
  • 6
  • 41
  • 63

1 Answers1

4

What we can observe from the memory usage graph is that the tabViewController is not being dismissed properly and it builds up in the stack. While dismissing you have to allow the viewController which presented the tabViewController to dismiss it. It is its responsibility to dismiss. Also keep weak references for Outlets and assign any strong references to nil** in viewWillDisapper: . You can present a viewController modally as a temporary interruption to obtain important information from the user. If its not the case here, you can remove presenting modally. Check this link. Hope this helps :)

Community
  • 1
  • 1
Meera
  • 1,031
  • 6
  • 25
  • I can't release it from memory manually, as I have ARC on. And even if I still have the method in the presented view controller, shouldn't [self.presentingViewController dismiss... Have the same affect as having the method in the view controller doing the presenting? Because even when I do that it still doesn't go away from memory. – Chris Loonam Jun 12 '13 at 10:49
  • Also, these are completely different view controllers and need to be presented modally. – Chris Loonam Jun 12 '13 at 10:52
  • @ChrisLoonam You dont have to release it,just make sure you use weak reference and set it nil. – Lithu T.V Jun 12 '13 at 11:28