﻿{"id":2684,"date":"2019-01-02T05:06:48","date_gmt":"2019-01-01T20:06:48","guid":{"rendered":"http:\/\/yucchi.jp\/blog\/?p=2684"},"modified":"2019-01-02T05:07:21","modified_gmt":"2019-01-01T20:07:21","slug":"weakreference","status":"publish","type":"post","link":"http:\/\/yucchi.jp\/blog\/?p=2684","title":{"rendered":"WeakReference"},"content":{"rendered":"<p>\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u306f\u3001SoftReference \u30a8\u30f3\u30c8\u30ea\u30fc\u306e\u7d9a\u304d\u3067\u3059\u3002<\/p>\n<p><a title=\"http:\/\/yucchi.jp\/blog\/?p=2675\" href=\"http:\/\/yucchi.jp\/blog\/?p=2675\">http:\/\/yucchi.jp\/blog\/?p=2675<\/a><\/p>\n<p>SoftReference \u3067\u7d44\u3093\u3060\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u5b9f\u884c\u7d50\u679c\u304c\u60f3\u50cf\u3057\u3066\u3044\u305f\u306e\u3068\u9055\u3063\u3066\u3044\u305f\u306e\u3067\u4eca\u5ea6\u306f WeakReference \u3067\u904a\u3093\u3067\u307f\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u3001WeakReference \u3063\u3066\u3069\u3093\u306a\u3082\u306e\u306a\u306e\u304b\u8abf\u3079\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>API\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u306f\u6b21\u306e\u3088\u3046\u306b\u8a18\u3055\u308c\u3066\u307e\u3059\u3002<\/p>\n<p><font color=\"#666666\">\u5f31\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u3059\u3002\u5f31\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u3001\u305d\u306e\u5f31\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30ea\u30d5\u30a1\u30ec\u30f3\u30c8\u304c\u30d5\u30a1\u30a4\u30ca\u30e9\u30a4\u30ba\u53ef\u80fd\u306b\u306a\u308a\u3001\u30d5\u30a1\u30a4\u30ca\u30e9\u30a4\u30ba\u3055\u308c\u3001\u305d\u3057\u3066\u518d\u751f\u3055\u308c\u308b\u3053\u3068\u3092\u963b\u6b62\u3059\u308b\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u5f31\u53c2\u7167\u306f\u3001\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u3067\u6b63\u898f\u5316\u30de\u30c3\u30d4\u30f3\u30b0\u3092\u5b9f\u88c5\u3059\u308b\u305f\u3081\u306b\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u3042\u308b\u6642\u70b9\u3067\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u5f31\u5230\u9054\u53ef\u80fd\u3067\u3042\u308b\u3068\u3001\u30ac\u30d9\u30fc\u30b8\u30fb\u30b3\u30ec\u30af\u30bf\u304c\u5224\u65ad\u3057\u305f\u3068\u3057\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u305d\u306e\u6642\u70b9\u3067\u3001\u30ac\u30d9\u30fc\u30b8\u30fb\u30b3\u30ec\u30af\u30bf\u306f\u3001\u305d\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3078\u306e\u5f31\u53c2\u7167\u3059\u3079\u3066\u3068\u3001\u5f37\u53c2\u7167\u304a\u3088\u3073\u30bd\u30d5\u30c8\u53c2\u7167\u306e\u30c1\u30a7\u30fc\u30f3\u3092\u7d4c\u7531\u3057\u3066\u305d\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u5230\u9054\u3067\u304d\u308b\u3088\u3046\u306a\u3001\u307b\u304b\u306e\u5f31\u5230\u9054\u53ef\u80fd\u306a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3078\u306e\u5f31\u53c2\u7167\u3059\u3079\u3066\u3092\u3001\u539f\u5b50\u7684\u306b\u30af\u30ea\u30a2\u3057\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u540c\u6642\u306b\u3001\u30ac\u30d9\u30fc\u30b8\u30fb\u30b3\u30ec\u30af\u30bf\u306f\u4ee5\u524d\u306b\u5f31\u5230\u9054\u53ef\u80fd\u306a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u3059\u3079\u3066\u30d5\u30a1\u30a4\u30ca\u30e9\u30a4\u30ba\u53ef\u80fd\u3067\u3042\u308b\u3053\u3068\u3092\u5ba3\u8a00\u3057\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u540c\u6642\u306b\u307e\u305f\u306f\u3042\u3068\u3067\u3001\u30ac\u30d9\u30fc\u30b8\u30fb\u30b3\u30ec\u30af\u30bf\u306f\u3001\u53c2\u7167\u30ad\u30e5\u30fc\u306b\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u305d\u308c\u3089\u306e\u65b0\u3057\u304f\u30af\u30ea\u30a2\u3055\u308c\u305f\u5f31\u53c2\u7167\u3092\u30ad\u30e5\u30fc\u306b\u5165\u308c\u307e\u3059\u3002 <\/font><\/p>\n<p>WeakReference \u3067\u306f\u5f31\u5230\u9054\u53ef\u80fd\u306b\u306a\u3063\u305f\u3089\u554f\u7b54\u7121\u7528\u3067\u4f55\u3082\u8003\u3048\u305a\u306b GC \u304c\u50cd\u304f\u3068\u304d\u306b\u7121\u6761\u4ef6\u3067\u53c2\u7167\u3092\u89e3\u653e\u3055\u308c\u308b\u3063\u3066\u3053\u3068\u304b\u306a\u3002<\/p>\n<p>SoftReference \u306e\u3088\u3046\u306b\u53c2\u7167\u306e\u4f7f\u7528\u983b\u5ea6\u3084\u30d2\u30fc\u30d7\u306e\u72b6\u6cc1\u3092\u8003\u616e\u3057\u3066\u53c2\u7167\u3092\u89e3\u653e\u3059\u308b\u306e\u3068\u306f\u5927\u9055\u3044\u3067\u3059\u306d\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u3053\u306e WeakReference \u306f\u3053\u306e\u7279\u6027\u3092\u3044\u304b\u3057\u3066 WeakHashMap \u306b\u4f7f\u308f\u308c\u3066\u3044\u307e\u3059\u306d\u3002<\/p>\n<p><font color=\"#666666\">java.util.WeakHashMap: \u30ad\u30fc\u304c\u5f31\u53ef\u5230\u9054\u306b\u306a\u3063\u305f\u3089\u30a8\u30f3\u30c8\u30ea\u3054\u3068\u524a\u9664\u3059\u308b Map<\/font><\/p>\n<p>WeakReference \u30af\u30e9\u30b9\u306b\u306f\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u304c\u4e8c\u3064\u3042\u308a\u307e\u3059\u3002<\/p>\n<p><font color=\"#666666\">WeakReference\u200b(T referent)<\/font><\/p>\n<p><font color=\"#666666\">\u6307\u5b9a\u3055\u308c\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u53c2\u7167\u3059\u308b\u3001\u65b0\u3057\u3044\u5f31\u53c2\u7167\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u65b0\u3057\u3044\u53c2\u7167\u306f\u3001\u3069\u306e\u30ad\u30e5\u30fc\u306b\u3082\u767b\u9332\u3055\u308c\u307e\u305b\u3093\u3002<\/font><\/p>\n<p><font color=\"#666666\">WeakReference\u200b(T referent, ReferenceQueue&lt;? super T&gt; q)<\/font><\/p>\n<p><font color=\"#666666\">\u6307\u5b9a\u3055\u308c\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u53c2\u7167\u3057\u3001\u6307\u5b9a\u3055\u308c\u305f\u30ad\u30e5\u30fc\u306b\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u65b0\u3057\u3044\u5f31\u53c2\u7167\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u30d1\u30e9\u30e1\u30fc\u30bf:referent &#8211; \u65b0\u3057\u3044\u5f31\u53c2\u7167\u304c\u53c2\u7167\u3059\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8q &#8211; \u53c2\u7167\u304c\u767b\u9332\u3055\u308c\u308b\u30ad\u30e5\u30fc\u3002\u767b\u9332\u304c\u5fc5\u8981\u306a\u3044\u5834\u5408\u306fnull<\/font><\/p>\n<p>\u30e1\u30bd\u30c3\u30c9\u306f\u7121\u3044\u3067\u3059\u306d\u3002<\/p>\n<p>\u305d\u308c\u3067\u306f\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u7d44\u3093\u3067\u8a66\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>\u524d\u56de\u7d44\u3093\u3060\u30d7\u30ed\u30b0\u30e9\u30e0\u3068\u540c\u3058\u3088\u3046\u306b\u7121\u99c4\u306b\u30e1\u30e2\u30ea\u30fc\u3092\u6d88\u8cbb\u3059\u308b\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u30921000\u500b\u4f5c\u3063\u3066\u3044\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u306b\u306f\u7121\u99c4\u306b\u30e1\u30e2\u30ea\u30fc\u3092\u6d88\u8cbb\u3059\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b finalize() \u30e1\u30bd\u30c3\u30c9\u3092\u5b9f\u88c5\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u7279\u306b\u305d\u308c\u306b\u3088\u3063\u3066\u4f55\u304b\u3059\u308b\u308f\u3051\u3067\u306a\u304f\u547c\u3070\u308c\u305f\u3053\u3068\u3092\u78ba\u8a8d\u3059\u308b\u305f\u3081\u3060\u3051\u3067\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<pre title=\"WeakReference_G1GC.java\"><code>\r\npackage jp.yucchi.weakreference_g1gc;\r\n\r\nimport java.lang.management.ManagementFactory;\r\nimport java.lang.ref.Reference;\r\nimport java.lang.ref.ReferenceQueue;\r\nimport java.lang.ref.WeakReference;\r\nimport java.util.ArrayList;\r\nimport java.util.List;\r\n\r\n\/**\r\n *\r\n * @author Yucchi\r\n *\/\r\npublic class WeakReference_G1GC {\r\n\r\n    private static final ReferenceQueue&lt;MemoryConsumer&gt; REFEREN_CEQUEU = new ReferenceQueue&lt;&gt;();\r\n\r\n    public static void main(String[] args) {\r\n        System.out.println(System.getProperty(\"os.name\") + \" \"\r\n                + System.getProperty(\"os.version\") + \" \" + System.getProperty(\"os.arch\"));\r\n        System.out.println(\"JDK \" + System.getProperty(\"java.version\") + System.lineSeparator());\r\n\r\n        List&lt;WeakReference&lt;MemoryConsumer&gt;&gt; list = new ArrayList&lt;&gt;();\r\n\r\n        for (int i = 0; i &lt; 1_000; i++) {\r\n            var memoryConsumer = new MemoryConsumer();\r\n            var weakReference = new WeakReference&lt;&gt;(memoryConsumer, REFEREN_CEQUEU);\r\n            list.add(weakReference);\r\n            checkStatus();\r\n        }\r\n\r\n    }\r\n\r\n    private static void checkStatus() {\r\n\r\n        var memoryBean = ManagementFactory.getMemoryMXBean();\r\n        var usage = memoryBean.getHeapMemoryUsage();\r\n        var usedMemory = usage.getUsed();\r\n        var gcMXBeans = ManagementFactory.getGarbageCollectorMXBeans();\r\n        var gcStatus = new StringBuilder();\r\n        gcMXBeans.forEach(e -&gt; {\r\n            gcStatus\r\n                    .append(e.getName())\r\n                    .append(\"   \")\r\n                    .append(\"GC Count: \")\r\n                    .append(e.getCollectionCount())\r\n                    .append(\"   \")\r\n                    .append(\"GCTime = \")\r\n                    .append(e.getCollectionTime())\r\n                    .append(\"     \");\r\n        });\r\n\r\n        System.out.print(\"UsedMemory: \" + usedMemory + \"   \");\r\n        System.out.println(gcStatus);\r\n\r\n        Reference&lt;?&gt; ref;\r\n        while ((ref = REFEREN_CEQUEU.poll()) != null) {\r\n            System.out.println(\"    --- POLL:\" + ref + \" ---\");\r\n        }\r\n\r\n    }\r\n\r\n    private static class MemoryConsumer {\r\n\r\n        private final byte[] buff;\r\n\r\n        MemoryConsumer() {\r\n            this.buff = new byte[100 * 1024 * 1024];\r\n        }\r\n\r\n        @Override\r\n        protected void finalize() {\r\n            System.out.println(\"    --- finalize() ---\");\r\n        }\r\n    }\r\n\r\n}\r\n\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u5b9f\u884c\u7d50\u679c\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>Windows 10 10.0 amd64<br \/>JDK 11.0.1<\/p>\n<p>UsedMemory: 113246208&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 222298112&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 331350016&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 440401920&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp; &#8212; finalize() &#8212;<br \/>&nbsp;&nbsp;&nbsp; &#8212; finalize() &#8212;<br \/>&nbsp;&nbsp;&nbsp; &#8212; finalize() &#8212;<br \/>&nbsp;&nbsp;&nbsp; &#8212; finalize() &#8212;<br \/>UsedMemory: 546492432&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 1&nbsp;&nbsp; GCTime = 3&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp; &#8212; POLL:java.lang.ref.WeakReference@d8355a8 &#8212;<br \/>&nbsp;&nbsp;&nbsp; &#8212; POLL:java.lang.ref.WeakReference@59fa1d9b &#8212;<br \/>&nbsp;&nbsp;&nbsp; &#8212; POLL:java.lang.ref.WeakReference@28d25987 &#8212;<br \/>&nbsp;&nbsp;&nbsp; &#8212; POLL:java.lang.ref.WeakReference@4501b7af &#8212;<br \/>&nbsp;&nbsp;&nbsp; &#8212; finalize() &#8212;<br \/>UsedMemory: 219385672&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 2&nbsp;&nbsp; GCTime = 6&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp; &#8212; POLL:java.lang.ref.WeakReference@523884b2 &#8212;<br \/>UsedMemory: 332631880&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 2&nbsp;&nbsp; GCTime = 6&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>\u7565<br \/>UsedMemory: 1201289840&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 115&nbsp;&nbsp; GCTime = 252&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 1310341744&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 115&nbsp;&nbsp; GCTime = 252&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 1419393648&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 115&nbsp;&nbsp; GCTime = 252&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0<\/p>\n<p>SoftReference \u3068\u306f\u5927\u9055\u3044\u3067\u3059\u3002<\/p>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u51e6\u7406\u6642\u9593\u308215\u79d2\u3068\u975e\u5e38\u306b\u77ed\u3044\u6642\u9593\u3067\u3059\u3002<\/p>\n<p>GC \u7d2f\u7a4d\u6642\u9593\u3082\u305c\u3093\u305c\u3093\u9055\u3044\u307e\u3059\u3002<\/p>\n<p>NetBeans \u306e\u30d7\u30ed\u30d5\u30a1\u30a4\u30e9\u3067\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/1-1.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"1\" style=\"border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px\" border=\"0\" alt=\"1\" src=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/1_thumb-1.png\" width=\"672\" height=\"571\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/2-1.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"2\" style=\"border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px\" border=\"0\" alt=\"2\" src=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/2_thumb-1.png\" width=\"687\" height=\"567\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/3-1.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"3\" style=\"border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px\" border=\"0\" alt=\"3\" src=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/3_thumb-1.png\" width=\"673\" height=\"581\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>SoftReference \u3068\u6bd4\u3079\u308b\u3068\u4f7f\u7528\u3057\u3066\u3044\u308b\u30d2\u30fc\u30d7\u30e1\u30e2\u30ea\u30fc\u30b5\u30a4\u30ba\u3082\u5168\u7136\u5c11\u306a\u3044\u3057\u3001GC \u30bf\u30a4\u30e0\u3082\u96f2\u6ce5\u306e\u5dee\u304c\u3042\u308b\u3002<\/p>\n<p>\u3053\u308c\u3092\u898b\u308b\u3068\u306a\u308b\u3060\u3051 SoftReference \u306f\u4f7f\u3044\u305f\u304f\u306a\u3044\u3068\u601d\u3063\u3066\u3057\u307e\u3046\u3002<\/p>\n<p>\u3067\u3082\u3001SoftReference \u3060\u3063\u305f\u3089\u30bd\u30d5\u30c8\u5230\u9054\u53ef\u80fd\u306a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3078\u306e\u3059\u3079\u3066\u306e\u30bd\u30d5\u30c8\u53c2\u7167\u306f\u3001\u4eee\u60f3\u30de\u30b7\u30f3\u304c OutOfMemoryError \u3092\u30b9\u30ed\u30fc\u3059\u308b\u524d\u306b\u30af\u30ea\u30a2\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u4fdd\u8a3c\u3055\u308c\u3066\u3044\u308b\u3002<\/p>\n<p>SoftReference \u306f\u30e1\u30e2\u30ea\u306e\u5bb9\u91cf\u306b\u5fdc\u3058\u3066\u30b9\u30b1\u30fc\u30eb\u3059\u308b\u30ad\u30e3\u30c3\u30b7\u30e5\u7528\u3063\u3066\u611f\u3058\u304b\u306a\u3002<\/p>\n<p>WeakReference \u306f\u5f31\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u5f31\u5230\u9054\u53ef\u80fd\u306b\u306a\u3063\u305f\u3089\u30ac\u30d9\u30fc\u30b8\u30fb\u30b3\u30ec\u30af\u30bf\u3067\u30af\u30ea\u30a2\u3057\u305f\u3044\u6642\u306b\u4f7f\u3046\uff08\u30ad\u30e3\u30c3\u30b7\u30e5\u3057\u306a\u3044\uff09\u3002<\/p>\n<p>API \u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306e\u6587\u7ae0\u304c\u96e3\u3057\u304f\u66f8\u304b\u308c\u3066\u3044\u308b\u306e\u3067\u3042\u307e\u308a\u81ea\u4fe1\u306f\u306a\u3044\u3051\u3069\u3053\u306e\u3088\u3046\u306a\u9055\u3044\u304c\u3042\u308b\u3088\u3046\u3060\u3002<\/p>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u5b9f\u884c\u7d50\u679c\u304b\u3089\u3082\u305d\u306e\u69d8\u5b50\u304c\u5c11\u3057\u306f\u89e3\u308a\u307e\u3059\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b SoftReference \u3068 WeakReference \u306e\u9055\u3044\u306f\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u51fa\u529b\u7d50\u679c\u306e\u30ac\u30d9\u30fc\u30b8\u30fb\u30b3\u30ec\u30af\u30bf\u306e\u52d5\u4f5c\u3067\u306f\u3063\u304d\u308a\u3068\u89e3\u308a\u307e\u3059\u3002<\/p>\n<p>WeakReference \u306e\u5f31\u5230\u9054\u53ef\u80fd\u306a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f Young Generation \u9818\u57df\u306b\u5bfe\u3059\u308b\u30de\u30a4\u30ca\u30fc GC \u3067\u3059\u3050\u56de\u53ce\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u306b\u5bfe\u3057\u3066 SoftReference \u306e\u30bd\u30d5\u30c8\u5230\u9054\u53ef\u80fd\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f G1 Old Generation \u9818\u57df\u306b\u79fb\u3055\u308c\u30d2\u30fc\u30d7\u304c\u4e0d\u8db3\u3057\u3066 OutOfMemoryError \u3092\u30b9\u30ed\u30fc\u3057\u306a\u3044\u3068\u3053\u308d\u307e\u3067\u56de\u53ce\u3055\u308c\u306a\u3044\u3088\u3046\u3067\u3059\u3002<\/p>\n<p><font color=\"#666666\">SoftReference: UsedMemory: 6871416088&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 222&nbsp;&nbsp; GCTime = 332&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 12&nbsp;&nbsp; GCTime = 8964 <\/font><\/p>\n<p><font color=\"#666666\">WeakReference: UsedMemory: 1419393648&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 115&nbsp;&nbsp; GCTime = 252&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0<\/font><\/p>\n<p>\u306a\u304b\u306a\u304b\u9762\u767d\u3044\u4ed5\u7d44\u307f\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u306d\u3002<\/p>\n<p>\u5f37\u53c2\u7167\u3057\u304b\u666e\u6bb5\u4f7f\u308f\u306a\u3044\u79c1\u306b\u3068\u3063\u3066\u65b0\u9bae\u306a\u6c17\u5206\u3067\u3059\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001\u3053\u308c\u3063\u3066 JDK 1.2 \u304b\u3089\u8ffd\u52a0\u3055\u308c\u305f\u53e4\u3044 API \u306e\u3088\u3046\u3067\u3059\u3002(^_^;)<\/p>\n<p>\u3044\u3063\u305f\u3044\u3069\u308c\u3060\u3051\u306e\u30d7\u30ed\u30b0\u30e9\u30de\u304c\u610f\u8b58\u3057\u3066\u4f7f\u3063\u3066\u3044\u308b\u306e\u304b\u3001\u3044\u3084\u30fb\u30fb\u30fb\u4f7f\u308f\u3056\u308b\u3092\u5f97\u306a\u304b\u3063\u305f\u306e\u304b\u30fb\u30fb\u30fb<\/p>\n<p>\u3055\u3066\u3001\u6b21\u306f PhantomReference \u3092\u8a66\u3057\u3066\u307f\u3088\u3046\u3002<\/p>\n<p>\u305f\u3076\u3093\u3001\u7d9a\u304f\u3002<\/p>\n<div id=\"scid:0767317B-992E-4b12-91E0-4F059A8CECA8:7344a434-4ddf-43f6-b622-3af15b3bce2b\" class=\"wlWriterEditableSmartContent\" style=\"float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px\">Hatena \u30bf\u30b0: <a href=\"http:\/\/b.hatena.ne.jp\/t\/java\" rel=\"tag\">java<\/a>,<a href=\"http:\/\/b.hatena.ne.jp\/t\/NetBeans\" rel=\"tag\">NetBeans<\/a><\/div>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_hatena\"><a href='\/\/b.hatena.ne.jp\/add?mode=confirm&url=http%3A%2F%2Fyucchi.jp%2Fblog%2F%3Fp%3D2684&title=WeakReference' title='\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0' rel=nofollow class='wp_social_bookmarking_light_a' target=_blank><img src='http:\/\/yucchi.jp\/blog\/wp-content\/plugins\/wp-social-bookmarking-light\/public\/images\/hatena.gif' alt='\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0' title='\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0' width='16' height='12' class='wp_social_bookmarking_light_img' \/><\/a><\/div>\n            <div class=\"wsbl_facebook\"><a href='http:\/\/www.facebook.com\/share.php?u=http%3A%2F%2Fyucchi.jp%2Fblog%2F%3Fp%3D2684&t=WeakReference' title='Facebook \u306b\u30b7\u30a7\u30a2' rel=nofollow class='wp_social_bookmarking_light_a' target=_blank><img src='http:\/\/yucchi.jp\/blog\/wp-content\/plugins\/wp-social-bookmarking-light\/public\/images\/facebook.png' alt='Facebook \u306b\u30b7\u30a7\u30a2' title='Facebook \u306b\u30b7\u30a7\u30a2' width='16' height='16' class='wp_social_bookmarking_light_img' \/><\/a><\/div>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"http:\/\/yucchi.jp\/blog\/?p=2684\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"http:\/\/yucchi.jp\/blog\/?p=2684\" data-text=\"WeakReference\" data-lang=\"ja\">Tweet<\/a><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u306f\u3001SoftReference \u30a8\u30f3\u30c8\u30ea\u30fc\u306e\u7d9a\u304d\u3067\u3059\u3002 http:\/\/yucchi.jp\/blog\/?p=2675 SoftReference \u3067\u7d44\u3093\u3060\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u5b9f\u884c\u7d50\u679c\u304c\u60f3\u50cf\u3057\u3066\u3044\u305f\u306e\u3068\u9055\u3063\u3066\u3044\u305f\u306e\u3067\u4eca\u5ea6\u306f WeakReference \u3067\u904a\u3093\u3067\u307f\u307e\u3059\u3002 \u307e\u305a\u3001WeakReference \u3063\u3066\u3069\u3093\u306a\u3082\u306e\u306a\u306e\u304b\u8abf\u3079\u3066\u307f\u307e\u3059\u3002 API\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u306f\u6b21\u306e\u3088\u3046\u306b\u8a18\u3055\u308c\u3066\u307e\u3059\u3002 \u5f31\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u3059\u3002\u5f31\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u3001\u305d\u306e\u5f31\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30ea\u30d5\u30a1\u30ec\u30f3\u30c8\u304c\u30d5\u30a1\u30a4\u30ca\u30e9\u30a4\u30ba\u53ef\u80fd\u306b\u306a\u308a\u3001\u30d5\u30a1\u30a4\u30ca\u30e9\u30a4\u30ba\u3055\u308c\u3001\u305d\u3057\u3066\u518d\u751f\u3055\u308c\u308b\u3053\u3068\u3092\u963b\u6b62\u3059\u308b\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3002 \u5f31\u53c2\u7167\u306f\u3001\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u3067\u6b63\u898f\u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[17,19],"class_list":["post-2684","post","type-post","status-publish","format-standard","hentry","category-java","category-netbeans","tag-java","tag-netbeans"],"_links":{"self":[{"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2684","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2684"}],"version-history":[{"count":1,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2684\/revisions"}],"predecessor-version":[{"id":2685,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2684\/revisions\/2685"}],"wp:attachment":[{"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2684"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2684"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2684"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}