开发者

Addressing a memory leak stops my UI from showing iphone

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];  comm开发者_JAVA技巧enting out this line removes the warning but results in no content being shown


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜