2013-02-17 44 views
0

我有一个来自UIDeviceRGBColor的泄漏。责任框架是+ [UIColor allocWithZone:]。我没有使用ARC。Xcode仪器泄漏来自UIDeviceRGBColor

泄漏来自下面的方法。

- (void) lAction 
{ 
MKCoordinateRegion mapRegion; 
mapRegion.center = mapView.userLocation.coordinate; 
mapRegion.span.latitudeDelta = 0.05; 
mapRegion.span.longitudeDelta = 0.05; 

[mapView setRegion:mapRegion animated: YES]; 

SettingsViewController *settingsViewController = [[SettingsViewController alloc] 
initWithNibName:@"SettingsViewController" bundle:nil]; 

泄漏从这个下一行来:

[self presentModalViewController: settingsViewController animated:YES]; 

然后,该方法完成这样的:

self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:40.0/255.0 
green:43.0/255.0 blue:46.0/255.0 alpha:1.0]; 
} 

任何人都知道如何解决这一问题?谢谢你们!

+2

如果您只是在发布问题之间等待8分钟,那么您应该尝试在发布之前自己找到更好的答案。 – 2013-02-17 04:45:54

+0

非常感谢 - 试图潜入记忆管理星云。经过了大约一千次的讨论,并且正在从专家那里收集更多的知识。 – Brandon 2013-02-17 04:48:47

+0

你可以从我的帖子看到我没有使用ARC。你会推荐我尝试转换我的项目吗? – Brandon 2013-02-17 04:50:04

回答

0

尝试:

SettingsViewController *settingsViewController = [[[SettingsViewController alloc] 
initWithNibName:@"SettingsViewController" bundle:nil] autorelease]; 

为了满足评议,解释很简单,如果你不使用ARC,只要您拨打alloc,将保留设置为1返回的对象的数量。你有责任释放它。一个简单的方法就是调用autorelease,它会在主运行循环结束时自动释放它(除非你正在管理自己的autorelease池,但我不会涉足)。你要确保,只要你需要使用一个对象的代码有什么保留它,在当你调用

[self presentModalViewController: settingsViewController animated:YES]; 

一个额外保留的呼吁settingViewController这种情况下,让你不当你的方法完成时,不得不担心它会被处理。

我发现Objective-C中的内存管理非常简单,但它确实需要额外的代码,而且现在每个人都使用ARC。如果您只是对现有代码库进行一些小修改,则不需要切换到ARC,但如果您要继续使用代码库一段时间,则切换时间效率更高。这很简单,因为Xcode将为您完成大部分工作。 (请参阅:http://developer.apple.com/library/ios/#releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html)。

+2

这不是一个答案。请提供解释如何解决这个问题。否则,这将更适合作为评论。 – 2013-02-17 04:47:40