UImage类方法和构造方法的缓存区别

创建 UIImage 对象时,可以使用类级构造方法 + imageNamed: 和实例构造方法 -initWithContentsOfFile: 。

+ imageNamed: 方法会在内存中建立缓存,这些缓存直到到应用停止才清除。如果是贯穿整个应用的图片(如图标、logo等) ,建议使用 + imageNamed: 创建;如果是仅使用一次的图片,推荐使用下面的语句:

NSString *path = [[NSBundle mainBundle] pathForResource:@"animal-2" ofType:@"png"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:path];
……
[image release];     //MRC下调用

  

posted on 2015-05-21 15:47  coderJin  阅读(123)  评论(0编辑  收藏  举报

导航