敬的世界

          常用鏈接

          統計

          最新評論

          weak reference

          A weak reference is one that does not prevent the referenced object from being garbage collected. You might use them to manage a HashMap to look up a cache of objects. A weak reference is a reference that does not keep the object it refers to alive. A weak reference is not counted as a reference in garbage collection. If the object is not referred to elsewhere as well, it will be garbage collected.

          The GC will send some sort of "finalize" message to the object and then set any weakly-referencing variables to null whenever it disposes of the referenced object. This allows "finalization" logic to be run before the object is disposed of (e.g., close a file if still open, commit any open transaction(s), etc.). Java 1.1 does not support weak references other than via an undocumented Ref class that is not supported under Netscape. Weak references arrived officially with JDK 1.2. Java has three kinds of weak references, called soft references, weak references, and phantom references, in order of increasing weakness.

          Java has four orders of strength in holding onto Objects. In descending order from strongest to weakest they are:

          1. The JVM holds onto regular Objects until they are no longer reachable by either clients or any container. In other words Objects are garbage collected when there are no more live references to them. Dead references don’t count.
          2. Soft references can be deleted from a container if the clients are no longer referencing them and memory is tight.
          3. Weak references are automatically deleted from a container as soon clients stop referencing them.
          4. Phantom references point to objects that are already dead and have been finalised.

          posted on 2009-05-17 00:12 picture talk 閱讀(264) 評論(0)  編輯  收藏 所屬分類: Java

          主站蜘蛛池模板: 黄骅市| 永定县| 雅江县| 苏尼特左旗| 清徐县| 延津县| 高雄市| 海口市| 陇西县| 台北县| 育儿| 洪洞县| 资源县| 保定市| 吉林省| 金坛市| 准格尔旗| 岗巴县| 晴隆县| 龙门县| 萍乡市| 瑞金市| 娄烦县| 壤塘县| 岳西县| 兰州市| 汕头市| 巴彦淖尔市| 白城市| 手游| 台前县| 永和县| 常熟市| 孝感市| 安顺市| 清苑县| 朝阳区| 信阳市| 石泉县| 东乌| 大同县|