用imageNamed加载图片产生的问题

通常我们会用imageNamed:来加载图片,但是用这个API有个问题,就是它会缓存加载的image。
因此,对于那些被重用的图片,这个API很高效。但是对于那些使用很少的图片,用这个就很耗内存,那怎么才能及时的释放掉内存呢?
使用initWithContentsOfFile:即可。
NSString path = [[NSBundle mainBundle] pathForResource:fileName ofType:fileType];
UIImage image = [[UIImage alloc] initWithContentsOfFile:path]; … [image release];
举个例子,程序第一次使用时,会加载很多新手引导图片, 如果用initWithContentsOfFile:,这些图片所占用内存可以很快被释放.
posted @ 2015-07-10 09:27  南非子  阅读(338)  评论(0编辑  收藏  举报