1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

UITabBarController and memory issues

Discussion in 'iPhone/iPad Programming' started by Reflejo, Dec 15, 2008.

  1. macrumors newbie


    I'm using a tabbarcontroller which i create programatically, when i release the controller without touch any tabitem dealloc works great and all viewcontrollers are deallocated. If i touch some tabBarItem after the realese, tabbarcontroller doesn't release viewcontrollers.

    There is a small example similar to what i'm doing.


    @property (assign, nonatomic) UITabBarController *tbController;

        NSMutableArray *tbControllers = [[NSMutableArray alloc] initWithCapacity:3];
        View1 *view1 = [[View1 alloc] init];
        view1.tabBarItem.title = @"1";
        [tbControllers addObject:view1];
        [view1 release];
        View2 *view2 = [[View2 alloc] init];
        view2.tabBarItem.title = @"1";
        [tbControllers addObject:view2];
        [view2 release];
        self.tbController = [[UITabBarController alloc] init];
        tbController.viewControllers = tbControllers;
        tbController.view.frame = CGRectMake(0,0, 320, 320);
        [tbControllers release];
        [self.view addSubview:tbController.view];

         [tbController release];
    View1 is an empty UIViewController with a debug output in viewDidLoad and dealloc. View2 too.

    - (void)viewDidLoad {
         NSLog(@"INIT view1");
         [super viewDidLoad];
    - (void)dealloc {
         NSLog(@"DEALLOCING 1");
         [super dealloc];
    I'm missing something or there is a bug?.
  2. macrumors newbie

    Also i've noticed that retainCount of each ViewController (inside tabbarController) increase by 1 every time i switch tabbaritem so when i release tabbarcontroller views are not deallocated.

    Any idea why?

    Thank you
  3. Moderator


    Staff Member

    In which method are you calling that Alloc code?

Share This Page