人在江湖

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            82 Posts :: 10 Stories :: 169 Comments :: 0 Trackbacks

          轉(zhuǎn)載自: http://www.java-tips.org/java-se-tips/java.util/using-weakhashmap-for-listener-lists.html

          In the Java platform, there are four types of references to objects. Direct references are the type you normally use, as in:

          Object obj = new Object()

          You can think of direct references as strong references that require no extra coding to create or access the object. The remaining three types of references are subclasses of the Reference class found in the java.lang.ref package. Soft references are provided by the SoftReference class, weak references by the WeakReference class, and phantom references by PhantomReference.

           
          Soft references act like a data cache. When system memory is low, the garbage collector can arbitrarily free an object whose only reference is a soft reference. In other words, if there are no strong references to an object, that object is a candidate for release. The garbage collector is required to release any soft references before throwing an OutOfMemoryException.


          Weak references are weaker than soft references. If the only references to an object are weak references, the garbage collector can reclaim the memory used by an object at any time. There is no requirement for a low memory situation. Typically, memory used by the object is reclaimed in the next pass of the garbage collector.


          Phantom references relate to cleanup tasks. They offer a notification immediately before the garbage collector performs the finalization process and frees an object. Consider it a way to do cleanup tasks within an object.

          posted on 2011-01-30 18:11 人在江湖 閱讀(361) 評(píng)論(0)  編輯  收藏 所屬分類: java
          主站蜘蛛池模板: 崇信县| 额敏县| 巴彦淖尔市| 竹溪县| 西乡县| 樟树市| 新和县| 凤城市| 尼木县| 同心县| 鸡泽县| 嵊州市| 凤庆县| 弥渡县| 固原市| 米林县| 岳普湖县| 运城市| 秦皇岛市| 古田县| 信丰县| 新巴尔虎左旗| 富民县| 义马市| 吴桥县| 和田市| 盐亭县| 洞头县| 马公市| 九江市| 南郑县| 临江市| 伊吾县| 陈巴尔虎旗| 手机| 武川县| 宾阳县| 景谷| 台山市| 汕尾市| 黎平县|