我尝试了2种为视图控制器创建背景图像的不同方法。在视图控制器中的背景图像导致内存增加+ UIColor colorWithPatternImage
我以前研究这一点,并得出结论,对于记忆力好做法,你应该使用这种方法:当使用其他方法
NSString *path = [[NSBundle mainBundle] pathForResource:@"controllerBackground" ofType:@"png" inDirectory:@""];
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:path]]];
:
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"controllerBackground.png"]]];
这是效率不高如使用imageWithContentsOfFile:路径方法。
但是,当使用性能工具“泄漏”监视器测试这两种方法时,我观察到一件非常不寻常的事情发生。
使用imageWithContentsOfFile:path
方法时,问题是,当在加载视图控制器的导航控制器内来回移动时,每次视图控制器加载时,内存将保持在大约1mb附近。
这个问题也只出现在新的iOS 4.1和4.它似乎没有发生在iOS 3.0或3.2。
bump ...任何人? – Allan 2010-10-24 23:21:31