在IOS4.3中如果我设置
navigationBar.tintColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1];
我会发生内存泄漏:UIDeviceRGBColor 泄漏
但是如果我使用 navigationBar.tintColor = [UIColor blackColor];
一切都很好。
这在 ios4.2 中从未发生过
我做了一些调试,我发现如果我使用 [navigationBar.tintColor retainCount]
似乎更大
[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1];
有没有人遇到同样的问题?
这是泄漏代码:
在 RootViewController 中:
- (void)viewWillAppear:(BOOL)animated {
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
[super viewWillAppear:animated];
}
在 DetailViewController 中:
- (void)viewWillAppear:(BOOL)animated {
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.9 green:0 blue:0 alpha:0];
[super viewWillAppear:animated];
}
如果你转到 DetailViewController,然后弹出到 RootViewController,在 Instruments 中,你可以看到 UIDeviceRGBColor 泄漏
最佳答案
我在 4.2 之前遇到过这个问题,我认为 colourWithRed:Green:blue 分配了一个你负责管理的新 UIColor 对象。
解决方案是为您的色调创建一个实例,并在您完成 viewDidUnload 中的导航 Controller 后释放它。
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
tintBarColor = [UIColor
colorWithRed:50.0/255
green:134.0/255
blue:187.0/255
alpha:1];
self.navigationController.navigationBar.tintColor = tintBarColor;
}
- (void)viewDidUnload
{
[super viewDidUnload];
[tintBarColor release];
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
}
关于iphone - IOS 4.3 UINavigationBar tintColor 泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5383090/