是否SoftReference调用.recycle()位图对象 [英] Does SoftReference calls .recycle() on Bitmap object
问题描述
如果我存储使用SoftReference一个HashMap中的位图,将SoftReference调用.recycle()上的位图?如果没有的话,这将是一种方法来清除位图正确地从内存中的特定情况下(当位图是一个HashMap中)?
如果我存储使用SoftReference一个HashMap中的位图,将SoftReference调用.recycle()上的位图?
没有。如果代替位图
您存储字符串
或一个POJO?他们是否有循环
的方法?当然不。所以,问题是:什么是 SoftReference
为
您使用
SoftReference
当你要活下去,直到主机进程运行时内存不足引用的对象。对象将没有资格领取直至采集器的需要的以释放内存。松松说,绑定SoftReference
表示,脚的对象,直到你不能了。 (<一href="http://stackoverflow.com/questions/3329691/understanding-javas-reference-classes-softreference-weakreference-and-phantom">link)
您不必在意清除位图(调用循环
法);只是让 SoftReference
做的工作。
If I store bitmaps in a hashmap using SoftReference, will SoftReference call .recycle() on the Bitmap ? And if it doesn't then what would be a way to clear the bitmap properly from memory under the given situation (when bitmaps are inside a HashMap) ?
If I store bitmaps in a hashmap using SoftReference, will SoftReference call .recycle() on the Bitmap ?
No. What if instead of a Bitmap
you store a String
or a POJO? Do they have the recycle
method? Of course no. So, the question is: what's SoftReference
for?
You use a
SoftReference
when you want the referenced object to stay alive until the host process is running low on memory. The object will not be eligible for collection until the collector needs to free memory. Loosely stated, binding aSoftReference
means, "Pin the object until you can't anymore." (link)
You don't have to care about clearing the Bitmap (invoking the recycle
method); just let the SoftReference
do its work.
这篇关于是否SoftReference调用.recycle()位图对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!