【发布时间】:2011-09-15 08:52:43
【问题描述】:
我以编程方式创建一个带有两个视图控制器的标签栏,如下面的代码。当我不再需要标签栏时,我发现很难清理内存。 Apple 的文档对于发布标签栏控制器非常有限。我不知道如何释放“viewControllers”数组中的所有视图控制器。我尝试打印出retain count,发现x & y的retainCount高达5。
@interface X:UIViewController
@interface Y:UIViewController
@interface Z: UIViewController {
UITabBarController *tabBar;
}
@end
@implementation Z
-(IBAction)openTabBarUp{
UITabBarController *tabBar = [[UITabBarController alloc] init];
X *x = [[X alloc] init];
Y *y = [[Y alloc] init];
tabBar.viewControllers = [NSArray arrayWithObjects: x, y, nil];
[self.view addSubView: tabBar.view];
}
这就是我尝试释放内存的方式:
-(IBAction)removeTabBar{
[tabBar.view removeFromSuperView];
[tabBar release];
tabBar = nil;
}
谢谢
狮子座
【问题讨论】:
-
一个对象的绝对retainCount是没有意义的。你在浪费时间去想它,
标签: iphone objective-c cocoa-touch uitabbarcontroller