关于软引用
来源:互联网 发布:java 事物的特征 编辑:程序博客网 时间:2024/06/06 10:49
A reference that is cleared when its referent is not strongly reachable and there is memory pressure.
Avoid Soft References for Caching
In practice, soft references are inefficient for caching. The runtime doesn't have enough information on which references to clear and which to keep. Most fatally, it doesn't know what to do when given the choice between clearing a soft reference and growing the heap.The lack of information on the value to your application of each reference limits the usefulness of soft references. References that are cleared too early cause unnecessary work; those that are cleared too late waste memory.
Most applications should use an android.util.LruCache
instead of soft references. LruCache has an effective eviction policy and lets the user tune how much memory is allotted.
Garbage Collection of Soft References
When the garbage collector encounters an objectobj
that is softly-reachable, the following happens:- A set
refs
of references is determined.refs
contains the following elements:- All soft references pointing to
obj
. - All soft references pointing to objects from which
obj
is strongly reachable.
- All soft references pointing to
- All references in
refs
are atomically cleared. - At the same time or some time in the future, all references in
refs
will be enqueued with their corresponding reference queues, if any.
SoftReference
s pointing to softly reachable objects will be cleared before the runtime throws anOutOfMemoryError
.Unlike a WeakReference
, a SoftReference
will not be cleared and enqueued until the runtime must reclaim memory to satisfy an allocation.
软引用不应该用来作为缓存!使用LruCache 才是推荐的方式。
0 0
- 关于软引用
- 关于Java四种引用包括强引用,软引用,弱引用,虚引用。
- 关于引用
- 关于“引用”
- 关于引用
- 关于引用
- 关于引用
- 关于引用
- 关于引用
- 关于引用
- 关于引用
- 关于引用
- 关于引用
- 关于引用
- 关于引用
- Java 关于强引用,软引用,弱引用和虚引用的区别与用法
- Java基础 关于强引用,软引用,弱引用,虚引用
- Java 关于强引用,软引用,弱引用和虚引用的区别与用法
- 极简的可用于测试的java对话框
- ubuntu下安装Docker
- eclipse安装找不到jre\bin\client\jvm.dll的问题
- HDU 4908 BestCoder Sequence(组合数学)
- 使用Xming + PuTTY在client端(window) 使用linux图形界面程序
- 关于软引用
- Scala 作业记录 00
- Hadoop2.4.0伪分布安装步骤
- activeX 组件修改 ——提高网络安全性
- Paste
- hdu1087 Super Jumping! Jumping! Jumping!
- Jquery Table 的基本操作
- HDU 4909 String(组合数学)
- 心情实验