我正在使用UITabbarcontroller获取内存泄漏警告。
如果我发布了tabbarcontroller,警告会消失,但标签栏不会显示任何内容。如果我调试应用程序并且警告仍在其中,则应用程序会运行,但会在几分钟后崩溃
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
答案 0 :(得分:1)
您需要在实例变量中存储对标签栏控制器的引用,并且只要您使用它就会保留它。否则控制器将在您释放后立即解除分配。