是否SoftReference调用.recycle()位图对象 [英] Does SoftReference calls .recycle() on Bitmap object

查看:155
本文介绍了是否SoftReference调用.recycle()位图对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我存储使用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 a SoftReference 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屋!

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