Iphone IOS 4.3 UINavigationBar着色泄漏

Iphone IOS 4.3 UINavigationBar着色泄漏,iphone,objective-c,ios4,Iphone,Objective C,Ios4,在IOS4.3中,如果我设置 navigationBar.tintColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1]; 我将得到一个内存泄漏:UIDeviceGBColor泄漏 但是如果我使用navigationBar.tintColor=[UIColor blackColor] 一切都很好 这在ios4.2中从未发生过 我做了一些调试,发现如果我使用 [UIColor colorWithRed:0.0 green:0.0

在IOS4.3中,如果我设置

navigationBar.tintColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1];
我将得到一个内存泄漏:UIDeviceGBColor泄漏

但是如果我使用
navigationBar.tintColor=[UIColor blackColor]
一切都很好

这在ios4.2中从未发生过

我做了一些调试,发现如果我使用

[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];
    } 
- (void)viewWillAppear:(BOOL)animated {
        self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.9 green:0 blue:0 alpha:0];
        [super viewWillAppear:animated];
    } 
详细信息请参见ViewController:

- (void)viewWillAppear:(BOOL)animated { 
        self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
        [super viewWillAppear:animated];
    } 
- (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泄漏

尝试使用构建和分析(或在Xcode 4中进行分析),并确保您没有先泄漏到其他地方。)如果仍然看到问题,请向Apple提交错误报告。

首先,不要使用
retainCount
。这是无用的

接下来,你怎么知道你有漏洞?你用过仪器吗?最后,您是否在分配工具中启用了保留事件跟踪,并查看了所有保留/发布的发送位置


+blackColor
是一个单身汉。因此,您很可能也在泄漏它,但只有一个,而且泄漏不会找到它,因为它被全局引用

至于你的漏洞,它是否只发生在iOS 4.3和4.2中并不重要。漏就是漏。虽然在苹果的框架中存在这种可能性,但这种可能性不大。然而,如果是这样的话,一个错误报告是高度赞赏的


此外,使用分配工具查看是否正在累积其他未显示为泄漏(但仍不应存在)的对象。泄漏只检测不可引用的对象,但还有许多其他方法泄漏内存

我可以在我的代码中确认相同的泄漏-在4.2中没有报告泄漏,在4.3中出现泄漏

我也看到了相同的问题。我已经向苹果公司提交了一个bug,我会发布我听到的任何更新

不过我找到了一个解决办法。问题在于调用self.navigationController.navigationBar.tintColor。但是,如果为不同的UIViewController设置色调颜色,则不会出现相同的问题。例如,这似乎没有泄漏:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetailViewController *detailViewController = [[DetailViewController alloc] initWithStyle:UITableViewStyleGrouped];
    detailViewController.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1];
    [self.navigationController pushViewController:detailViewController animated:YES];
    [detailViewController release];
}
不幸的是,这对我们这些使用Three20框架的人没有帮助=(


更新:我收到苹果的回复。他们说已经有报道了,他们正在调查这个问题。

我在4.2之前就有这个问题,我认为colorWithred:Green:blue分配了一个新的UIColor对象,你负责管理它

解决方案是为色调创建一个实例,并在完成viewDidUnload中的导航控制器后将其释放

- (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;
}

这确实是有线的。我在ios4.2和ios4.3上使用相同的代码在仪器中运行,ios4.2没有此问题。我使用仪器来监控泄漏和分配。如果我使用
navigationBar.tintColor=[uicolorWithred:0.0 green:0.0 blue:0.0 alpha:1]
在viewwillbeen中出现。泄漏只发生在ios4.3中。非常感谢您的帮助。我已经向苹果公司报告了。我刚刚编辑了问题,添加了一些代码。您能否创建一个非常简单的项目,它有两个屏幕:rootviewcontroller和detailviewcontroller。并设置视图中的色调将出现在每个viewController中。您可以请注意仪器的泄漏。非常感谢你的帮助。谢谢你确认这不仅仅是我。使用这个很久了,从来没有出现过问题。奇怪的是,它只是偶尔发生。