views:

33

answers:

1

Hi

I've being getting a memory leak warning with a UITabbarcontroller.

If I release the tabbarcontroller the warning goes away but the tabbar will not show any content. If I debug the app with the warning still in it the app runs but will crash after a couple of minutes

UITabBarController *tabBarController = [[UITabBarController alloc] init];   
    tabBarController.view.frame = CGRectMake(0, 0, 320, 460);   
    tabBarController.viewControllers=localControllersArray;
    // Clean up objects we don't need anymore
    [promoTabOptionHome release];
    [promoTabOptionInfo release];
    [promoTabOptionEvents release];
    [promoTabOptionBuy release];
     [localControllersArray release];

    // Finally, add the tab controller view to the parent view
    [self.view addSubview:tabBarController.view];
    //[tabBarController release];  commenting out this line removes the warning but results in no content being shown
+1  A: 

You need to store a reference to the tab bar controller in an instance variable and retain it as long as you use it. Otherwise the controller will get deallocated as soon as you release it.

Ole Begemann
I made the tab bar controller a member of the class and set it to release in the dealloc function. Thanks
dubbeat