Skip to content

Instantly share code, notes, and snippets.

@zhangkn
Last active June 4, 2018 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhangkn/8b5b8342808f6a7ca620a5123c5d187c to your computer and use it in GitHub Desktop.
Save zhangkn/8b5b8342808f6a7ca620a5123c5d187c to your computer and use it in GitHub Desktop.
//方式一:有缓存(图片所占用的内存会一直停留在程序中)
+ (UIImage *)imageNamed:(NSString *)name;//name是图片的文件名
//方式二:无缓存(图片所占用的内存会在一些特定操作后被清除)
+ (UIImage *)imageWithContentsOfFile:(NSString *)path
- (id)initWithContentsOfFile:(NSString *)path;//path是图片的全路径
//1、imageNamed 方式加载图片,内存由系统负责,
//即使帧图片对象数组失去animationImage数组的强引用,仍然会保存在内存
//2. 无缓存加载方式
[arrayImage addObject:[ UIImage imageWithContentsOfFile:path]];
//当帧图片对象数组没有任何强参照引用时,立即被释放,占用内存少些
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment