UIImage的缓存行为 [英] Caching behavior of UIImage

查看:76
本文介绍了UIImage的缓存行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UIImage 是否曾经从其缓存中删除图像?我是否可以保留指向从 imageNamed:获得的图像的指针,并在需要时使用它,或者必须始终调用 imageNamed:

Does UIImage ever removes images from its cache? Can I keep a pointer to an image I got from imageNamed: and use it as long as I like or must I always call imageNamed:?

推荐答案

从中返回的 UIImage 对象就内存管理而言, imageNamed:被视为与所有其他对象一样。如果要在两次方法调用之间保留对对象的引用,则在使用时应保留,并 release

The UIImage object that is returned from imageNamed: is treated like all other objects as far a memory management goes. If you want to keep the reference to the object between method calls, you should retain it and release it when you are done to decrement the reference count.

UIImage * cachedImage;

-(void) getTheImage {
  UIImage * cachedImage = [[UImage imageNamed:@"MyImage.png"] retain];
  //Do something with the image...
}
//In some other method or dealloc
[cachedImage release];

此外,请注意 UIImage类引用说:


在内存不足的情况下,图像数据
可能会从UIImage对象中清除到
,从而释放系统上的内存。 这种
清除行为仅影响
UIImage对象内部存储的
图像数据,而不影响对象
本身。
b $ b图像的数据已清除后,
图像对象会自动从其原始文件中重新加载$ ​​b $ b数据。但是,此
额外的负载步骤可能会导致
小小的性能损失。

In low-memory situations, image data may be purged from a UIImage object to free up memory on the system. This purging behavior affects only the image data stored internally by the UIImage object and not the object itself. When you attempt to draw an image whose data has been purged, the image object automatically reloads the data from its original file. This extra load step, however, may incur a small performance penalty.

这篇关于UIImage的缓存行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆