﻿{"id":2714,"date":"2019-01-03T06:21:39","date_gmt":"2019-01-02T21:21:39","guid":{"rendered":"http:\/\/yucchi.jp\/blog\/?p=2714"},"modified":"2019-01-03T11:41:29","modified_gmt":"2019-01-03T02:41:29","slug":"phantomreference","status":"publish","type":"post","link":"http:\/\/yucchi.jp\/blog\/?p=2714","title":{"rendered":"PhantomReference"},"content":{"rendered":"<p>\u304a\u6b63\u6708\u4f11\u307f\u3082\u4eca\u65e5\u3067\u7d42\u308f\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<p>\u4f55\u51e6\u306b\u3082\u51fa\u304b\u3051\u305a\u5bb6\u3067\u3054\u308d\u3054\u308d\u3057\u3066\u3044\u307e\u3057\u305f\u3002(^_^;)<\/p>\n<p>\u5c45\u5834\u6240\u306b\u56f0\u308b\u306e\u3067\u3053\u3046\u3084\u3063\u3066\u30d1\u30bd\u30b3\u30f3\u3067\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u7d44\u3093\u3067\u6642\u9593\u3092\u7121\u99c4\u306b\u4f7f\u3063\u3066\u307e\u3059\u3002<\/p>\n<p>\u4eca\u65e5\u306f PhantomReference \u3092\u8a66\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e\u524d\u306b\u524d\u56de\u3001\u524d\u3005\u56de\u3068 PhantomReference \u306e\u5144\u5f1f\u306e <a href=\"http:\/\/yucchi.jp\/blog\/?p=2675\" target=\"_blank\">SoftReference<\/a> \u3068 <a href=\"http:\/\/yucchi.jp\/blog\/?p=2684\" target=\"_blank\">WeakReference<\/a> \u306e\u5fa1\u6d5a\u3044\u3092\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>SoftReference \u306f\u30ea\u30d5\u30a1\u30ec\u30f3\u30c8\u304c\u30bd\u30d5\u30c8\u5230\u9054\u53ef\u80fd\u3068\u306a\u3063\u3066\u3082\u4f7f\u7528\u983b\u5ea6\u3068\u30d2\u30fc\u30d7\u306e\u72b6\u6cc1\u304b\u3089\u3001\u30ac\u30fc\u30d9\u30fc\u30b8\u30fb\u30b3\u30ec\u30af\u30bf\u304c\u30ea\u30d5\u30a1\u30ec\u30f3\u30c8\u3092\u89e3\u653e\u3059\u3079\u304d\u3060\u3068\u5224\u65ad\u3059\u308b\u307e\u3067 GC \u5bfe\u8c61\u306b\u306a\u3089\u306a\u3044\u3002<\/p>\n<p>Weak Reference \u306f\u30ea\u30d5\u30a1\u30ec\u30f3\u30c8\u304c\u5f31\u5230\u9054\u53ef\u80fd\u3068\u306a\u3063\u305f\u3089 GC \u5bfe\u8c61\u3068\u306a\u308b\u3002<\/p>\n<p>\u8a00\u8449\u3067\u306e\u8aac\u660e\u3088\u308a\u7c21\u5358\u306a\u30d7\u30ed\u30b0\u30e9\u30e0\u3068\u7d44\u3093\u3067\u5b9f\u884c\u3057\u3066\u307f\u305f\u307b\u3046\u304c\u7406\u89e3\u3057\u3084\u3059\u3044\u3067\u3059\u3002<\/p>\n<p>\u3067\u306f\u3001\u975e\u5e38\u306b\u89e3\u308a\u3084\u3059\u3044\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u7d44\u3093\u3067\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u4e2d\u306b\u3044\u308b\u201d\u307c\u304f\u201d\u306f\u3042\u306a\u305f\u306e\u5834\u5408\u3001SoftReference \u30bf\u30a4\u30d7\u3067\u3057\u3087\u3046\u304b\uff1f<\/p>\n<p>\u305d\u308c\u3068\u3082 Weak Reference \u30bf\u30a4\u30d7\u3067\u3057\u3087\u3046\u304b\uff1f<\/p>\n<p>&nbsp;<\/p>\n<pre title=\"SoftLoveReference.java\"><code>\r\npackage jp.yucchi.softlovereference;\r\n\r\nimport java.lang.ref.Reference;\r\nimport java.lang.ref.SoftReference;\r\n\r\n\/**\r\n *\r\n * @author Yucchi\r\n *\/\r\npublic class SoftLoveReference {\r\n\r\n    public static void main(String[] args) {\r\n\r\n        var softLoveReference = new SoftLoveReference();\r\n\r\n        \/\/ suzu \u3092\u30bd\u30d5\u30c8\u5230\u9054\u53ef\u80fd\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u3059\u308b\u3002(boku \u304b\u3089 suzu \u306e\u5f37\u53c2\u7167\u3092\u524a\u9664)\r\n        softLoveReference.boku.suzu = null;\r\n        System.out.println(\"--- \u50d5\u304b\u3089\u3059\u305a\u3078\u306e\u611b\u3092\u7121\u304f\u3057\u305f\u3002 ---\");\r\n\r\n        \/\/ \u30bd\u30d5\u30c8\u5230\u9054\u53ef\u80fd\u3068\u306a\u3063\u305f suzu \u306f\u3059\u3050\u306b\u30ac\u30fc\u30d9\u30b8\u30fb\u30b3\u30ec\u30af\u30c8\u5bfe\u8c61\u3068\u306a\u3089\u305a\u306b\r\n        \/\/ \u30d2\u30fc\u30d7\u306e\u7a7a\u304d\u5bb9\u91cf\u304c\u4e0d\u8db3\u3057\u305f\u3068\u304d\u306b\u56de\u53ce\u5bfe\u8c61\u3068\u306a\u308b\u3002\r\n        System.gc();\r\n\r\n        \/\/ \u30ea\u30d5\u30a1\u30ec\u30f3\u30c8\u3092\u53d6\u5f97\r\n        var love = softLoveReference.boku.yui.suzu;\r\n        if (love.get() != null) {\r\n            \/\/ \u30bd\u30d5\u30c8\u5230\u9054\u53ef\u80fd\u30aa\u30d6\u30b8\u30a7\u30af\u30c8 suzu \u306f\u307e\u3060\u6d88\u3048\u3066\u3044\u306a\u3044\u3002\r\n            love.get().isLove();\r\n            \/\/ \u30ea\u30d5\u30a1\u30ec\u30f3\u30c8\u3092\u30af\u30ea\u30a2\u3059\u308b\u3002\r\n            love.clear();\r\n            if (love.get() == null) {\r\n                \/\/ \u30bd\u30d5\u30c8\u5230\u9054\u53ef\u80fd\u30aa\u30d6\u30b8\u30a7\u30af\u30c8 suzu \u306f\u6d88\u3048\u3066\u3044\u308b\u3002\r\n                System.out.println(\"\u30ac\u30c3\u30ad\u30fc\u3001\u4eca\u307e\u3067\u3054\u3081\u3093\u306d\u3002\u50d5\u306e\u3059\u305a\u3078\u306e\u611b\u306f\u5b8c\u5168\u306b\u6d88\u3048\u305f\u3002\" + System.lineSeparator()\r\n                        + \"\u3053\u308c\u304b\u3089\u306f\u30ac\u30c3\u30ad\u30fc\u304a\u524d\u3060\u3051\u3092\u611b\u3059\u308b\uff01\");\r\n            }\r\n        } else {\r\n            \/\/ \u30bd\u30d5\u30c8\u5230\u9054\u53ef\u80fd\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u6d88\u3048\u3066\u3044\u308b\u3002\r\n            System.out.println(\"\u50d5\u306e\u3059\u305a\u3078\u306e\u611b\u306f\u5b8c\u5168\u306b\u6d88\u3048\u305f\u3002\");\r\n        }\r\n\r\n    }\r\n\r\n    Boku boku;\r\n\r\n    public SoftLoveReference() {\r\n        boku = new Boku();\r\n        boku.yui = new Yui();\r\n        boku.suzu = new Suzu();\r\n        \/\/ yui \u304b\u3089 suzu \u306f\u30bd\u30d5\u30c8\u53c2\u7167\r\n        boku.yui.suzu = new SoftReference&lt;&gt;(boku.suzu);\r\n    }\r\n\r\n    private static class Boku {\r\n\r\n        Boku() {\r\n            System.out.println(\"\u50d5\u306f\u4e8c\u4eba\u306e\u7d20\u6575\u306a\u5973\u6027\u3092\u611b\u3057\u3066\u3057\u307e\u3063\u305f\u3002\");\r\n        }\r\n\r\n        Yui yui;\r\n        Suzu suzu;\r\n\r\n    }\r\n\r\n    private static class Yui {\r\n\r\n        Yui() {\r\n            System.out.println(\"\u50d5\u306f\u30ac\u30c3\u30ad\u30fc\u3092\u611b\u3057\u3066\u308b\u3002\");\r\n        }\r\n\r\n        \/\/ \u53c2\u7167\u578b\u30d5\u30a3\u30fc\u30eb\u30c9\r\n        Reference&lt;Suzu&gt; suzu = null;\r\n\r\n    }\r\n\r\n    private static class Suzu {\r\n\r\n        Suzu() {\r\n            System.out.println(\"\u50d5\u306f\u3059\u305a\u3092\u611b\u3057\u3066\u308b\u3002\");\r\n        }\r\n\r\n        void isLove() {\r\n            System.out.println(\"\u3054\u3081\u3093\u306d\u3002\u30ac\u30c3\u30ad\u30fc\u30fb\u30fb\u30fb\u3000\u50d5\u306e\u3059\u305a\u3078\u306e\u611b\u306f\u307e\u3060\u5b8c\u5168\u306b\u6d88\u3048\u3066\u3044\u306a\u3044\u3002\");\r\n        }\r\n\r\n    }\r\n\r\n}\r\n\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u3053\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u5b9f\u884c\u7d50\u679c\u306f\u3064\u304e\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><font color=\"#666666\">\u50d5\u306f\u4e8c\u4eba\u306e\u7d20\u6575\u306a\u5973\u6027\u3092\u611b\u3057\u3066\u3057\u307e\u3063\u305f\u3002<br \/>\u50d5\u306f\u30ac\u30c3\u30ad\u30fc\u3092\u611b\u3057\u3066\u308b\u3002<br \/>\u50d5\u306f\u3059\u305a\u3092\u611b\u3057\u3066\u308b\u3002<br \/>&#8212; \u50d5\u304b\u3089\u3059\u305a\u3078\u306e\u611b\u3092\u7121\u304f\u3057\u305f\u3002 &#8212;<br \/>\u3054\u3081\u3093\u306d\u3002\u30ac\u30c3\u30ad\u30fc\u30fb\u30fb\u30fb\u3000\u50d5\u306e\u3059\u305a\u3078\u306e\u611b\u306f\u307e\u3060\u5b8c\u5168\u306b\u6d88\u3048\u3066\u3044\u306a\u3044\u3002<br \/>\u30ac\u30c3\u30ad\u30fc\u3001\u4eca\u307e\u3067\u3054\u3081\u3093\u306d\u3002\u50d5\u306e\u3059\u305a\u3078\u306e\u611b\u306f\u5b8c\u5168\u306b\u6d88\u3048\u305f\u3002<br \/>\u3053\u308c\u304b\u3089\u306f\u30ac\u30c3\u30ad\u30fc\u304a\u524d\u3060\u3051\u3092\u611b\u3059\u308b\uff01<\/font><\/p>\n<p>\u6b21\u306f Weak Reference \u3092\u4f7f\u3063\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<pre title=\"WeakLoveReference.java\"><code>\r\npackage jp.yucchi.weaklovereference;\r\n\r\nimport java.lang.ref.Reference;\r\nimport java.lang.ref.WeakReference;\r\n\r\n\/**\r\n *\r\n * @author Yucchi\r\n *\/\r\npublic class WeakLoveReference {\r\n\r\n    public static void main(String[] args) {\r\n\r\n        var weakLoveReference = new WeakLoveReference();\r\n\r\n        \/\/ suzu \u3092\u5f31\u5230\u9054\u53ef\u80fd\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u3059\u308b\u3002(boku \u304b\u3089 suzu \u306e\u5f37\u53c2\u7167\u3092\u524a\u9664)\r\n        weakLoveReference.boku.suzu = null;\r\n        System.out.println(\"--- \u50d5\u304b\u3089\u3059\u305a\u3078\u306e\u611b\u3092\u7121\u304f\u3057\u305f\u3002 ---\");\r\n\r\n        \/\/ \u5f31\u5230\u9054\u53ef\u80fd\u3068\u306a\u3063\u305f suzu \u306f\u30ac\u30fc\u30d9\u30b8\u30fb\u30b3\u30ec\u30af\u30c8\u306e\u56de\u53ce\u4f53\u5236\u3068\u306a\u308b\u3002\r\n        System.gc();\r\n\r\n        \/\/ \u30ea\u30d5\u30a1\u30ec\u30f3\u30c8\u3092\u53d6\u5f97\r\n        var love = weakLoveReference.boku.yui.suzu;\r\n        \/\/ \u5f31\u5230\u9054\u53ef\u80fd\u30aa\u30d6\u30b8\u30a7\u30af\u30c8 suzu \u306f\u6d88\u3048\u3066\u3044\u308b\u3002\r\n        if (love.get() != null) { \/\/ true \u306e\u90e8\u5206\u306f\u5b9f\u884c\u3055\u308c\u308b\u3053\u3068\u306f\u306a\u3044\u3002      \r\n            love.get().isLove();\r\n            love.clear();\r\n            if (love.get() == null) {\r\n                System.out.println(\"\u30ac\u30c3\u30ad\u30fc\u3001\u4eca\u307e\u3067\u3054\u3081\u3093\u306d\u3002\u50d5\u306e\u3059\u305a\u3078\u306e\u611b\u306f\u5b8c\u5168\u306b\u6d88\u3048\u305f\u3002\" + System.lineSeparator()\r\n                        + \"\u3053\u308c\u304b\u3089\u306f\u30ac\u30c3\u30ad\u30fc\u304a\u524d\u3060\u3051\u3092\u611b\u3059\u308b\uff01\");\r\n            }\r\n        } else {\r\n            \/\/ \u5f31\u5230\u9054\u53ef\u80fd\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u6d88\u3048\u3066\u3044\u308b\u3002\r\n            System.out.println(\"\u50d5\u306e\u3059\u305a\u3078\u306e\u611b\u306f\u5b8c\u5168\u306b\u6d88\u3048\u305f\u3002\u3000\u30ac\u30c3\u30ad\u30fc\u3001\u611b\u3057\u3066\u308b\uff01\");\r\n        }\r\n\r\n    }\r\n\r\n    Boku boku;\r\n\r\n    public WeakLoveReference() {\r\n        boku = new Boku();\r\n        boku.yui = new Yui();\r\n        boku.suzu = new Suzu();\r\n        \/\/ yui \u304b\u3089 suzu \u5f31\u53c2\u7167\r\n        boku.yui.suzu = new WeakReference&lt;&gt;(boku.suzu);\r\n    }\r\n\r\n    private static class Boku {\r\n\r\n        Boku() {\r\n            System.out.println(\"\u50d5\u306f\u4e8c\u4eba\u306e\u7d20\u6575\u306a\u5973\u6027\u3092\u611b\u3057\u3066\u3057\u307e\u3063\u305f\u3002\");\r\n        }\r\n\r\n        Yui yui;\r\n        Suzu suzu;\r\n\r\n    }\r\n\r\n    private static class Yui {\r\n\r\n        Yui() {\r\n            System.out.println(\"\u50d5\u306f\u30ac\u30c3\u30ad\u30fc\u3092\u611b\u3057\u3066\u308b\u3002\");\r\n        }\r\n\r\n        \/\/ \u53c2\u7167\u578b\u30d5\u30a3\u30fc\u30eb\u30c9\r\n        Reference&lt;Suzu&gt; suzu = null;\r\n\r\n    }\r\n\r\n    private static class Suzu {\r\n\r\n        Suzu() {\r\n            System.out.println(\"\u50d5\u306f\u3059\u305a\u3092\u611b\u3057\u3066\u308b\u3002\");\r\n        }\r\n\r\n        void isLove() {\r\n            System.out.println(\"\u3054\u3081\u3093\u306d\u3002\u30ac\u30c3\u30ad\u30fc\u30fb\u30fb\u30fb\u3000\u50d5\u306e\u3059\u305a\u3078\u306e\u611b\u306f\u307e\u3060\u5b8c\u5168\u306b\u6d88\u3048\u3066\u3044\u306a\u3044\u3002\");\r\n        }\r\n\r\n    }\r\n\r\n}\r\n\r\n<\/code><\/pre>\n<p>\u3053\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u5b9f\u884c\u7d50\u679c\u306f\u3064\u304e\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><font color=\"#666666\">\u50d5\u306f\u4e8c\u4eba\u306e\u7d20\u6575\u306a\u5973\u6027\u3092\u611b\u3057\u3066\u3057\u307e\u3063\u305f\u3002<br \/>\u50d5\u306f\u30ac\u30c3\u30ad\u30fc\u3092\u611b\u3057\u3066\u308b\u3002<br \/>\u50d5\u306f\u3059\u305a\u3092\u611b\u3057\u3066\u308b\u3002<br \/>&#8212; \u50d5\u304b\u3089\u3059\u305a\u3078\u306e\u611b\u3092\u7121\u304f\u3057\u305f\u3002 &#8212;<br \/>\u50d5\u306e\u3059\u305a\u3078\u306e\u611b\u306f\u5b8c\u5168\u306b\u6d88\u3048\u305f\u3002\u3000\u30ac\u30c3\u30ad\u30fc\u3001\u611b\u3057\u3066\u308b\uff01<\/font><\/p>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u8a73\u7d30\u306f\u30b3\u30e1\u30f3\u30c8\u3068\u524d\u56de\u3001\u524d\u3005\u56de\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u307e\u305b\u3002<\/p>\n<p>\u3055\u3066\u3001\u3042\u306a\u305f\u306f\u3069\u3061\u3089\u306e\u30bf\u30a4\u30d7\u3067\u3057\u305f\u3067\u3057\u3087\u3046\uff1f<\/p>\n<p>\u305d\u308c\u3067\u306f PhantomReference \u3092\u8a66\u3057\u3066\u307f\u307e\u3057\u3087\u3046\uff01<\/p>\n<p>PhantomReference \u3092\u4f7f\u3046\u306b\u306f \u30e2\u30b8\u30e5\u30fc\u30eb java.base \u306e java.lang.Object java.lang.ref.ReferenceQueue&lt;T&gt; \u30af\u30e9\u30b9\u304c\u5fc5\u8981\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u3046\u3044\u3048\u3070\u3001\u30e2\u30b8\u30e5\u30fc\u30eb java.base \u306e java.lang.Object java.lang.ref.Reference&lt;T&gt; \u306e\u3053\u3068\u3082\u5fd8\u308c\u3066\u3044\u305f\u306e\u3067\u3053\u308c\u3089\u3092\u5148\u306b\u3056\u3063\u304f\u308a\u3068\u8abf\u3079\u307e\u3059\u3002<\/p>\n<p>\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u305f\u3081\u306e\u62bd\u8c61\u57fa\u5e95\u30af\u30e9\u30b9\u3067\u3042\u308b Reference&lt;T&gt; \u30af\u30e9\u30b9\u304b\u3089\u8abf\u3079\u307e\u3059\u3002<\/p>\n<p><strong><font size=\"4\"><font color=\"#000000\">\u30af\u30e9\u30b9<\/font>Reference&lt;T&gt; <\/font><\/strong><\/p>\n<p><font color=\"#666666\">\u3053\u306e\u30af\u30e9\u30b9\u306f\u3001\u3059\u3079\u3066\u306e\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u5bfe\u3057\u3066\u5171\u901a\u306e\u30aa\u30da\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u5b9a\u7fa9\u3057\u307e\u3059\u3002<\/font><\/p>\n<p><font color=\"#666666\">\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u30ac\u30d9\u30fc\u30b8\u30fb\u30b3\u30ec\u30af\u30bf\u3068\u5bc6\u63a5\u306b\u9023\u643a\u3057\u3066\u5b9f\u88c5\u3055\u308c\u308b\u306e\u3067\u3001\u3053\u306e\u30af\u30e9\u30b9\u3092\u76f4\u63a5\u30b5\u30d6\u30af\u30e9\u30b9\u5316\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002<\/font><\/p>\n<p>\u30e1\u30bd\u30c3\u30c9\u306f\uff16\u500b\u3042\u308a\u307e\u3059\u3002<\/p>\n<p><font size=\"3\"><strong>public void clear()<\/strong><\/font><\/p>\n<p><font color=\"#666666\">\u3053\u306e\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u30af\u30ea\u30a2\u3057\u307e\u3059\u3002 \u3053\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u3066\u3082\u3001\u3053\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u30ad\u30e5\u30fc\u306b\u5165\u308a\u307e\u305b\u3093\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u306fJava\u30b3\u30fc\u30c9\u306b\u3088\u3063\u3066\u306e\u307f\u547c\u3073\u51fa\u3055\u308c\u307e\u3059\u3002\u30ac\u30d9\u30fc\u30b8\u30fb\u30b3\u30ec\u30af\u30bf\u304c\u53c2\u7167\u3092\u30af\u30ea\u30a2\u3059\u308b\u3068\u304d\u306f\u3001\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3055\u305a\u306b\u76f4\u63a5\u884c\u3044\u307e\u3059\u3002<\/font><\/p>\n<p><font color=\"#666666\">protected Object clone()throws CloneNotSupportedException<\/font><\/p>\n<p><font color=\"#666666\">\u5e38\u6642 CloneNotSupportedException\u3092\u30b9\u30ed\u30fc\u3057\u307e\u3059\u3002 Reference\u306f\u3001\u52b9\u679c\u7684\u306b\u30af\u30ed\u30fc\u30cb\u30f3\u30b0\u3067\u304d\u307e\u305b\u3093\u3002 \u304b\u308f\u308a\u306b\u65b0\u898f\u306eReference\u3092\u69cb\u7bc9\u3057\u307e\u3059<\/font>\u3002 <\/p>\n<p><strong><font size=\"3\">public boolean enqueue()<\/font><\/strong><\/p>\n<p><font color=\"#666666\">\u3053\u306e\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u30af\u30ea\u30a2\u3057\u3001\u305d\u308c\u304c\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u30ad\u30e5\u30fc\u306b\u767b\u9332\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u306fJava\u30b3\u30fc\u30c9\u306b\u3088\u3063\u3066\u306e\u307f\u547c\u3073\u51fa\u3055\u308c\u307e\u3059\u3002\u30ac\u30d9\u30fc\u30b8\u30fb\u30b3\u30ec\u30af\u30bf\u304c\u53c2\u7167\u3092\u30ad\u30e5\u30fc\u306b\u5165\u308c\u308b\u3068\u304d\u306f\u3001\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3055\u305a\u306b\u76f4\u63a5\u884c\u3044\u307e\u3059\u3002<\/font><\/p>\n<p><font color=\"#666666\">\u623b\u308a\u5024:\u3053\u306e\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u30ad\u30e5\u30fc\u306b\u5165\u308c\u3089\u308c\u305f\u5834\u5408\u306ftrue\u3002\u3059\u3067\u306b\u30ad\u30e5\u30fc\u306b\u5165\u308c\u3089\u308c\u3066\u3044\u308b\u304b\u3001\u4f5c\u6210\u6642\u306b\u30ad\u30e5\u30fc\u306b\u767b\u9332\u3055\u308c\u306a\u304b\u3063\u305f\u5834\u5408\u306ffalse<\/font><\/p>\n<p><strong><font size=\"3\">public T get()<\/font><\/strong><\/p>\n<p><font color=\"#666666\">\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30ea\u30d5\u30a1\u30ec\u30f3\u30c8\u3092\u8fd4\u3057\u307e\u3059\u3002 \u30d7\u30ed\u30b0\u30e9\u30e0\u307e\u305f\u306f\u30ac\u30d9\u30fc\u30b8\u30fb\u30b3\u30ec\u30af\u30bf\u306b\u3088\u3063\u3066\u3001\u3053\u306e\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u3059\u3067\u306b\u30af\u30ea\u30a2\u3055\u308c\u3066\u3044\u308b\u5834\u5408\u3001\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u306fnull\u3092\u8fd4\u3057\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u623b\u308a\u5024:\u3053\u306e\u53c2\u7167\u304c\u8868\u3059\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3002\u3053\u306e\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u30af\u30ea\u30a2\u3055\u308c\u3066\u3044\u308b\u5834\u5408\u306fnull<\/font><\/p>\n<p><font size=\"3\"><strong>public boolean isEnqueued()<\/strong><\/font><\/p>\n<p><font color=\"#666666\">\u3053\u306e\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u307e\u305f\u306f\u30ac\u30d9\u30fc\u30b8\u30fb\u30b3\u30ec\u30af\u30bf\u306b\u3088\u3063\u3066\u30ad\u30e5\u30fc\u306b\u5165\u308c\u3089\u308c\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u3092\u5224\u5b9a\u3057\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u3053\u306e\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u751f\u6210\u3055\u308c\u305f\u3068\u304d\u306b\u30ad\u30e5\u30fc\u306b\u767b\u9332\u3055\u308c\u3066\u3044\u306a\u3044\u5834\u5408\u3001\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u306f\u5e38\u306bfalse\u3092\u8fd4\u3057\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u623b\u308a\u5024:\u3053\u306e\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u30ad\u30e5\u30fc\u306b\u5165\u308c\u3089\u308c\u3066\u3044\u308b\u5834\u5408\u306b\u3060\u3051true<\/font><\/p>\n<p><font size=\"3\"><strong>public static void reachabilityFence\u200b(Object ref)<\/strong><\/font><\/p>\n<p><font color=\"#666666\">\u6307\u5b9a\u3055\u308c\u305f\u53c2\u7167\u306b\u3088\u3063\u3066\u53c2\u7167\u3055\u308c\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u5230\u9054\u4e0d\u80fd\u306b\u306a\u308b\u53ef\u80fd\u6027\u306e\u3042\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u4ee5\u524d\u306e\u30a2\u30af\u30b7\u30e7\u30f3\u306b\u95a2\u4fc2\u306a\u304f\u3001\u300c\u5f37\u304f\u5230\u9054\u53ef\u80fd\u306a\u300d\u306e\u307e\u307e\u3067\u3042\u308b\u3053\u3068\u3092\u4fdd\u8a3c\u3057\u307e\u3059\u3002<\/font><\/p>\n<p><font color=\"#666666\">\u3053\u306e\u305f\u3081\u3001\u53c2\u7167\u3055\u308c\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u3001\u5c11\u306a\u304f\u3068\u3082\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u304c\u547c\u3073\u51fa\u3055\u308c\u308b\u307e\u3067\u30ac\u30d9\u30fc\u30b8\u30fb\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u306b\u3088\u3063\u3066\u518d\u8981\u6c42\u3067\u304d\u307e\u305b\u3093<\/font>\u3002<\/p>\n<p>\u6b21\u306f\u30e2\u30b8\u30e5\u30fc\u30eb java.base \u306e java.lang.Object java.lang.ref.ReferenceQueue&lt;T&gt; \u3092\u8abf\u3079\u3066\u307f\u307e\u3059\u3002<\/p>\n<p><strong><font size=\"4\">\u30af\u30e9\u30b9ReferenceQueue&lt;T&gt;<\/font><\/strong><\/p>\n<p><font color=\"#666666\">\u53c2\u7167\u30ad\u30e5\u30fc\u3067\u3059\u3002\u5230\u9054\u53ef\u80fd\u6027\u304c\u9069\u5207\u306b\u5909\u66f4\u3055\u308c\u305f\u3053\u3068\u304c\u691c\u51fa\u3055\u308c\u308b\u3068\u3001\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u30ac\u30d9\u30fc\u30b8\u30fb\u30b3\u30ec\u30af\u30bf\u306b\u3088\u3063\u3066\u53c2\u7167\u30ad\u30e5\u30fc\u306b\u8ffd\u52a0\u3055\u308c\u307e\u3059\u3002<\/font><\/p>\n<p>\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306f\u5f15\u6570\u306e\u7121\u3044\u3082\u306e\u304c\u4e00\u3064\u3060\u3051\u3042\u308a\u307e\u3059\u3002<\/p>\n<p><font color=\"#000000\" size=\"3\"><strong>public ReferenceQueue()<\/strong><\/font><\/p>\n<p><font color=\"#666666\">\u65b0\u3057\u3044\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u30fb\u30ad\u30e5\u30fc\u3092\u69cb\u7bc9\u3057\u307e\u3059\u3002<\/font><\/p>\n<p>\u30e1\u30bd\u30c3\u30c9\u306f\uff13\u500b\u3042\u308a\u307e\u3059\u3002<\/p>\n<p><strong><font size=\"3\">public Reference&lt;? extends T&gt; poll()<\/font><\/strong><\/p>\n<p><font color=\"#666666\">\u3053\u306e\u30ad\u30e5\u30fc\u3092\u30dd\u30fc\u30ea\u30f3\u30b0\u3057\u3066\u3001\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u5229\u7528\u53ef\u80fd\u304b\u3069\u3046\u304b\u3092\u78ba\u8a8d\u3057\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u9045\u5ef6\u306a\u3057\u3067\u5229\u7528\u53ef\u80fd\u306a\u5834\u5408\u3001\u305d\u308c\u304c\u30ad\u30e5\u30fc\u304b\u3089\u524a\u9664\u3055\u308c\u3066\u3001\u8fd4\u3055\u308c\u307e\u3059\u3002 \u305d\u308c\u4ee5\u5916\u306e\u5834\u5408\u3001\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u306f\u5373\u5ea7\u306bnull\u3092\u8fd4\u3057\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u623b\u308a\u5024:\u5229\u7528\u53ef\u80fd\u306a\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u3042\u3063\u305f\u5834\u5408\u306f\u305d\u306e\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3001\u305d\u3046\u3067\u306a\u3044\u5834\u5408\u306fnull<\/font><\/p>\n<p><strong><font size=\"3\">public Reference&lt;? extends T&gt; remove()throws InterruptedException<\/font><\/strong><\/p>\n<p><font color=\"#666666\">\u3053\u306e\u30ad\u30e5\u30fc\u306e\u6b21\u306e\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u524a\u9664\u3057\u307e\u3059\u3002\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u5229\u7528\u53ef\u80fd\u306b\u306a\u308b\u307e\u3067\u30d6\u30ed\u30c3\u30af\u3055\u308c\u307e\u3059\u3002<\/font><\/p>\n<p><font color=\"#666666\">\u623b\u308a\u5024:\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u30021\u3064\u304c\u5229\u7528\u53ef\u80fd\u306b\u306a\u308b\u307e\u3067\u30d6\u30ed\u30c3\u30af\u3092\u884c\u3046<\/font><\/p>\n<p><font color=\"#666666\">\u4f8b\u5916:InterruptedException &#8211; \u5f85\u6a5f\u4e2d\u306b\u5272\u308a\u8fbc\u307e\u308c\u305f\u5834\u5408<\/font><\/p>\n<p><font color=\"#000000\" size=\"3\"><strong>public Reference&lt;? extends T&gt; remove\u200b(long timeout)throws IllegalArgumentException, InterruptedException<\/strong><\/font><\/p>\n<p><font color=\"#666666\">\u3053\u306e\u30ad\u30e5\u30fc\u306e\u6b21\u306e\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u524a\u9664\u3057\u307e\u3059\u3002\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u5229\u7528\u53ef\u80fd\u306b\u306a\u308b\u304b\u3001\u6307\u5b9a\u3055\u308c\u305f\u30bf\u30a4\u30e0\u30fb\u30a2\u30a6\u30c8\u306e\u671f\u9650\u304c\u5207\u308c\u308b\u307e\u3067\u30d6\u30ed\u30c3\u30af\u3057\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u306f\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u4fdd\u8a3c\u3092\u884c\u3044\u307e\u305b\u3093\u3002Object.wait(long)\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u305f\u5834\u5408\u3068\u540c\u69d8\u306b\u30bf\u30a4\u30e0\u30fb\u30a2\u30a6\u30c8\u306e\u30b9\u30b1\u30b8\u30e5\u30fc\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/font><\/p>\n<p><font color=\"#666666\">\u30d1\u30e9\u30e1\u30fc\u30bf:timeout &#8211; \u5024\u304c\u6b63\u306e\u5834\u5408\u3001\u3053\u306e\u30ad\u30e5\u30fc\u306b\u53c2\u7167\u304c\u8ffd\u52a0\u3055\u308c\u308b\u306e\u3092\u5f85\u3064\u9593\u3001timeout\u30df\u30ea\u79d2\u306e\u9593\u30d6\u30ed\u30c3\u30af\u3055\u308c\u308b\u3002 0\u306e\u5834\u5408\u3001\u7121\u671f\u9650\u306b\u30d6\u30ed\u30c3\u30af\u3055\u308c\u308b\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u623b\u308a\u5024:\u6307\u5b9a\u3055\u308c\u305f\u30bf\u30a4\u30e0\u30fb\u30a2\u30a6\u30c8\u671f\u9593\u306b\u5229\u7528\u53ef\u80fd\u306b\u306a\u3063\u305f\u5834\u5408\u306f\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3001\u305d\u3046\u3067\u306a\u3044\u5834\u5408\u306fnull<\/font><\/p>\n<p><font color=\"#666666\">\u4f8b\u5916:IllegalArgumentException &#8211; timeout\u5f15\u6570\u306e\u5024\u304c\u8ca0\u306e\u5834\u5408<br \/>InterruptedException &#8211; \u30bf\u30a4\u30e0\u30fb\u30a2\u30a6\u30c8\u5f85\u6a5f\u4e2d\u306b\u5272\u308a\u8fbc\u307e\u308c\u305f\u5834\u5408<\/font><\/p>\n<p>\u305d\u308c\u3067\u306f\u6b21\u306f\u30e2\u30b8\u30e5\u30fc\u30eb java.base \u306e java.lang.Object java.lang.ref.Reference&lt;T&gt; java.lang.ref.PhantomReference&lt;T&gt; \u30af\u30e9\u30b9\u3092\u8abf\u3079\u307e\u3059\u3002<\/p>\n<p><font size=\"4\"><strong>\u30af\u30e9\u30b9PhantomReference&lt;T&gt;<\/strong><\/font><\/p>\n<p><font color=\"#666666\">\u30d5\u30a1\u30f3\u30c8\u30e0\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u3059\u3002\u30d5\u30a1\u30f3\u30c8\u30e0\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u30ad\u30e5\u30fc\u306b\u5165\u308c\u3089\u308c\u308b\u306e\u306f\u3001\u30ad\u30e5\u30fc\u306b\u5165\u308c\u3066\u304a\u304b\u306a\u3044\u3068\u305d\u308c\u3089\u306e\u30ea\u30d5\u30a1\u30ec\u30f3\u30c8\u304c\u518d\u751f\u3055\u308c\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u3068\u30b3\u30ec\u30af\u30bf\u304c\u5224\u65ad\u3057\u305f\u3068\u304d\u3067\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u5e7b\u306e\u53c2\u7167\u306f\u3001\u6b7b\u5f8c\u306e\u30af\u30ea\u30fc\u30f3\u30a2\u30c3\u30d7\u30fb\u30a2\u30af\u30b7\u30e7\u30f3\u3092\u30b9\u30b1\u30b8\u30e5\u30fc\u30eb\u3059\u308b\u305f\u3081\u306b\u6700\u3082\u983b\u7e41\u306b\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u3042\u308b\u6642\u70b9\u3067\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u300c\u30d5\u30a1\u30f3\u30c8\u30e0\u5230\u9054\u53ef\u80fd\u300d\u3067\u3042\u308b\u3068\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\u305d\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3078\u306e\u3059\u3079\u3066\u306e\u30d5\u30a1\u30f3\u30c8\u30e0\u53c2\u7167\u3068\u3001\u305d\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u5230\u9054\u53ef\u80fd\u306a\u4ed6\u306e\u30d5\u30a1\u30f3\u30c8\u30e0\u5230\u9054\u53ef\u80fd\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3078\u306e\u3059\u3079\u3066\u306e\u30d5\u30a1\u30f3\u30c8\u30e0\u53c2\u7167\u3092\u539f\u5b50\u7684\u306b\u30af\u30ea\u30a2\u3057\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u540c\u6642\u306b\u3001\u307e\u305f\u306f\u5f8c\u3067\u3001\u53c2\u7167\u30ad\u30e5\u30fc\u306b\u767b\u9332\u3055\u308c\u305f\u305d\u308c\u3089\u306e\u65b0\u305f\u306b\u30af\u30ea\u30a2\u3055\u308c\u305f\u30d5\u30a1\u30f3\u30c8\u30e0\u53c2\u7167\u3092\u30a8\u30f3\u30ad\u30e5\u30fc\u3057\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u518d\u751f\u53ef\u80fd\u306a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u305d\u306e\u307e\u307e\u306b\u3057\u3066\u304a\u304f\u305f\u3081\u306b\u3001\u30d5\u30a1\u30f3\u30c8\u30e0\u53c2\u7167\u306e\u30ea\u30d5\u30a1\u30ec\u30f3\u30c8\u3092\u53d6\u308a\u51fa\u3059\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002\u30d5\u30a1\u30f3\u30c8\u30e0\u53c2\u7167\u306eget\u30e1\u30bd\u30c3\u30c9\u306f\u3001\u5e38\u306bnull\u3092\u8fd4\u3057\u307e\u3059\u3002<\/font><\/p>\n<p>\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306f\u5f15\u6570\u3092\u4e8c\u3064\u53d6\u308b\u3082\u306e\u304c\u4e00\u3064\u3060\u3051\u3042\u308a\u307e\u3059\u3002<\/p>\n<p><strong><font size=\"3\">public PhantomReference\u200b(T referent, ReferenceQueue&lt;? super T&gt; q)<\/font><\/strong><\/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\u30d5\u30a1\u30f3\u30c8\u30e0\u53c2\u7167\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">null\u30ad\u30e5\u30fc\u3067\u30d5\u30a1\u30f3\u30c8\u30e0\u30fb\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u306f\u53ef\u80fd\u3067\u3059\u304c\u3001\u305d\u306e\u3088\u3046\u306a\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u306f\u307e\u3063\u305f\u304f\u5f79\u306b\u7acb\u305f\u306a\u3044: \u305d\u306eget\u30e1\u30bd\u30c3\u30c9\u306f\u5e38\u306bnull\u3092\u8fd4\u3057\u3001\u30ad\u30e5\u30fc\u3092\u6301\u305f\u306a\u3044\u306e\u3067\u30a8\u30f3\u30ad\u30e5\u30fc\u3055\u308c\u307e\u305b\u3093\u3002<\/font><\/p>\n<p><font color=\"#666666\">\u30d1\u30e9\u30e1\u30fc\u30bf:referent &#8211; \u65b0\u3057\u3044\u30d5\u30a1\u30f3\u30c8\u30e0\u53c2\u7167\u304c\u53c2\u7167\u3059\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<br \/>q &#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\u4e00\u3064\u3060\u3051\u3042\u308a\u307e\u3059\u3002<\/p>\n<p><strong><font size=\"3\">public T get()<\/font><\/strong><\/p>\n<p><font color=\"#666666\">\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30ea\u30d5\u30a1\u30ec\u30f3\u30c8\u3092\u8fd4\u3057\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u30d5\u30a1\u30f3\u30c8\u30e0\u53c2\u7167\u306e\u30ea\u30d5\u30a1\u30ec\u30f3\u30c8\u306f\u5e38\u306b\u30a2\u30af\u30bb\u30b9\u4e0d\u53ef\u80fd\u306a\u305f\u3081\u3001\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u306f\u5e38\u306bnull\u3092\u8fd4\u3057\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u623b\u308a\u5024:null<\/font><\/p>\n<p>\u3053\u308c\u3067 PhantomReference \u3092\u4f7f\u3046\u305f\u3081\u306e API \u3092\u307f\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u3068\u3001\u601d\u3044\u304d\u3084 JDK 9 \u304b\u3089 java.\u200blang.\u200bObject protected void finalize() throws Throwable \u304c Deprecated \u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u4ee3\u308f\u308a\u306b\u30e2\u30b8\u30e5\u30fc\u30eb java.base \u306e java.lang.Object java.lang.ref.Cleaner \u30af\u30e9\u30b9\u3092\u4f7f\u3046\u3053\u3068\u304c\u63a8\u5968\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3053\u3061\u3089\u3082\u3056\u3063\u304f\u308a\u3068\u307f\u3066\u307f\u307e\u3059\u3002<\/p>\n<p><strong><font size=\"4\">\u30af\u30e9\u30b9Cleaner<\/font><\/strong><\/p>\n<p><font color=\"#666666\">Cleaner\u306f\u3001\u4e00\u9023\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u53c2\u7167\u3068\u5bfe\u5fdc\u3059\u308b\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u30fb\u30a2\u30af\u30b7\u30e7\u30f3\u3092\u7ba1\u7406\u3057\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u30af\u30ea\u30fc\u30ca\u306f\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u6709\u7dda\u3067\u5230\u9054\u53ef\u80fd\u306b\u306a\u3063\u305f\u3053\u3068\u304c\u30af\u30ea\u30fc\u30ca\u306b\u901a\u77e5\u3055\u308c\u305f\u5f8c\u3067\u5b9f\u884c\u3059\u308b\u305f\u3081\u306b\u3001\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u52d5\u4f5c\u306fregistered\u3067\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u30af\u30ea\u30fc\u30ca\u306f\u3001PhantomReference\u3068ReferenceQueue\u3092\u4f7f\u7528\u3057\u3066\u3001reachability\u304c\u5909\u66f4\u3055\u308c\u305f\u3068\u304d\u306b\u901a\u77e5\u3092\u53d7\u3051\u53d6\u308a\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u5404\u30af\u30ea\u30fc\u30ca\u306f\u3001\u72ec\u7acb\u3057\u3066\u52d5\u4f5c\u3057\u3001\u4fdd\u7559\u4e2d\u306e\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u52d5\u4f5c\u3092\u7ba1\u7406\u3057\u3001\u30af\u30ea\u30fc\u30ca\u304c\u3059\u3067\u306b\u4f7f\u7528\u3055\u308c\u3066\u3044\u306a\u3044\u3068\u304d\u306b\u30b9\u30ec\u30c3\u30c9\u304a\u3088\u3073\u7d42\u4e86\u3092\u51e6\u7406\u3057\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u53c2\u7167\u3068\u5bfe\u5fdc\u3059\u308b\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u30fb\u30a2\u30af\u30b7\u30e7\u30f3\u3092\u767b\u9332\u3059\u308b\u3068\u3001Cleanable\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002 \u6700\u3082\u52b9\u7387\u7684\u306a\u4f7f\u7528\u6cd5\u306f\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u9589\u3058\u3089\u308c\u305f\u308a\u4e0d\u8981\u306b\u306a\u3063\u305f\u3068\u304d\u306b\u3001clean\u30e1\u30bd\u30c3\u30c9\u3092\u660e\u793a\u7684\u306b\u547c\u3073\u51fa\u3059\u3053\u3068\u3067\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u30fb\u30a2\u30af\u30b7\u30e7\u30f3\u306f\u3001\u3059\u3067\u306b\u660e\u793a\u7684\u306b\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u3055\u308c\u3066\u3044\u306a\u3044\u9650\u308a\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u30d5\u30a1\u30f3\u30c8\u30e0\u5230\u9054\u53ef\u80fd\u306b\u306a\u3063\u305f\u3068\u304d\u306b\u547c\u3073\u51fa\u3055\u308c\u308bRunnable\u3067\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u52d5\u4f5c\u306f\u3001\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u53c2\u7167\u3057\u3066\u306f\u306a\u3089\u306a\u3044\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002 \u305d\u3046\u3067\u3042\u308c\u3070\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u60f3\u50cf\u3092\u7d76\u3059\u308b\u3082\u306e\u306b\u306a\u3089\u305a\u3001\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u52d5\u4f5c\u306f\u81ea\u52d5\u7684\u306b\u547c\u3073\u51fa\u3055\u308c\u307e\u305b\u3093\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u30fb\u30a2\u30af\u30b7\u30e7\u30f3\u306e\u5b9f\u884c\u306f\u3001\u30af\u30ea\u30fc\u30ca\u306b\u95a2\u9023\u3059\u308b\u30b9\u30ec\u30c3\u30c9\u306b\u3088\u3063\u3066\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u30fb\u30a2\u30af\u30b7\u30e7\u30f3\u306b\u3088\u3063\u3066\u30b9\u30ed\u30fc\u3055\u308c\u305f\u3059\u3079\u3066\u306e\u4f8b\u5916\u306f\u7121\u8996\u3055\u308c\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u30af\u30ea\u30fc\u30ca\u304a\u3088\u3073\u305d\u306e\u4ed6\u306e\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u30fb\u30a2\u30af\u30b7\u30e7\u30f3\u306f\u3001\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u30fb\u30a2\u30af\u30b7\u30e7\u30f3\u306e\u4f8b\u5916\u306e\u5f71\u97ff\u3092\u53d7\u3051\u307e\u305b\u3093\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u30b9\u30ec\u30c3\u30c9\u306f\u3001\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u3059\u3079\u3066\u306e\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u51e6\u7406\u304c\u5b8c\u4e86\u3057\u3001\u30af\u30ea\u30fc\u30ca\u81ea\u4f53\u304c\u30ac\u30d9\u30fc\u30b8\u30fb\u30b3\u30ec\u30af\u30bf\u306b\u3088\u3063\u3066\u518d\u5229\u7528\u3055\u308c\u308b\u307e\u3067\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">System.exit\u4e2d\u306e\u30af\u30ea\u30fc\u30ca\u306e\u52d5\u4f5c\u306f\u5b9f\u88c5\u56fa\u6709\u3067\u3059\u3002 \u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u52d5\u4f5c\u306e\u547c\u3073\u51fa\u3057\u306e\u6709\u7121\u306f\u4fdd\u8a3c\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u307b\u304b\u3067\u6307\u5b9a\u304c\u306a\u3044\u5834\u5408\u3001null\u5f15\u6570\u3092\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u307e\u305f\u306f\u3053\u306e\u30af\u30e9\u30b9\u306e\u30e1\u30bd\u30c3\u30c9\u3078\u6e21\u3059\u3068\u3001NullPointerException\u304c\u30b9\u30ed\u30fc\u3055\u308c\u307e\u3059\u3002<\/font><\/p>\n<p>\u30cd\u30b9\u30c8\u3055\u308c\u305f\u30af\u30e9\u30b9\u304c\u4e00\u3064\u3042\u308a\u307e\u3059\u3002<\/p>\n<p><strong><font size=\"3\">public static interface Cleaner.Cleanable<\/font><\/strong><\/p>\n<p><font color=\"#666666\">Cleanable\u306f\u3001Cleaner\u306b\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u30fb\u30a2\u30af\u30b7\u30e7\u30f3\u3092\u8868\u3057\u307e\u3059\u3002<\/font><\/p>\n<p>\u30cd\u30b9\u30c8\u3055\u308c\u305f\u30af\u30e9\u30b9\u306b\u30e1\u30bd\u30c3\u30c9\u304c\u4e00\u3064\u3060\u3051\u3042\u308a\u307e\u3059\u3002<\/p>\n<p><strong><font size=\"3\">void clean()<\/font><\/strong><\/p>\n<p><font color=\"#666666\">\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u53ef\u80fd\u306a\u3082\u306e\u306e\u767b\u9332\u3092\u89e3\u9664\u3057\u3001\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u52d5\u4f5c\u3092\u547c\u3073\u51fa\u3057\u307e\u3059\u3002 \u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u53ef\u80fd\u306a\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u52d5\u4f5c\u306f\u3001clean\u306e\u547c\u3073\u51fa\u3057\u56de\u6570\u306b\u95a2\u4fc2\u306a\u304f\u3001\u6700\u5927\u30671\u56de\u547c\u3073\u51fa\u3055\u308c\u307e\u3059\u3002<\/font> <\/p>\n<p>Cleaner \u30af\u30e9\u30b9\u306b\u306f\u30e1\u30bd\u30c3\u30c9\u304c\uff13\u500b\u3042\u308a\u307e\u3059\u3002<\/p>\n<p><strong><font size=\"3\">public static Cleaner create()<\/font><\/strong><\/p>\n<p><font color=\"#666666\">\u65b0\u3057\u3044Cleaner\u3092\u8fd4\u3057\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u30af\u30ea\u30fc\u30ca\u306f\u3001\u30d5\u30a1\u30f3\u30c8\u30e0\u5230\u9054\u53ef\u80fd\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u51e6\u7406\u3057\u3001\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u30fb\u30a2\u30af\u30b7\u30e7\u30f3\u3092\u547c\u3073\u51fa\u3059daemon thread\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u30b9\u30ec\u30c3\u30c9\u306e\u300c\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u30fb\u30af\u30e9\u30b9\u30fb\u30ed\u30fc\u30c0\u30fc\u300d\u306fsystem class loader\u306b\u8a2d\u5b9a\u3055\u308c\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u30b9\u30ec\u30c3\u30c9\u306f\u30d1\u30fc\u30df\u30c3\u30b7\u30e7\u30f3\u3092\u6301\u305f\u305a\u3001SecurityManager is set\u306e\u5834\u5408\u306b\u306e\u307f\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u30d5\u30a1\u30f3\u30c8\u30e0\u306b\u5230\u9054\u3057\u3001\u767b\u9332\u3055\u308c\u305f\u3059\u3079\u3066\u306e\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u52d5\u4f5c\u304c\u5b8c\u4e86\u3059\u308b\u3068\u3001\u30af\u30ea\u30fc\u30ca\u306f\u7d42\u4e86\u3057\u307e\u3059\u3002<\/font><\/p>\n<p><font color=\"#666666\">\u623b\u308a\u5024:\u65b0\u3057\u3044Cleaner<\/font><\/p>\n<p><font color=\"#666666\">\u4f8b\u5916:SecurityException &#8211; \u73fe\u5728\u306e\u30b9\u30ec\u30c3\u30c9\u304c\u30b9\u30ec\u30c3\u30c9\u306e\u4f5c\u6210\u307e\u305f\u306f\u958b\u59cb\u3092\u8a31\u53ef\u3055\u308c\u3066\u3044\u306a\u3044\u5834\u5408<\/font>\u3002<\/p>\n<p><strong><font size=\"3\">public static Cleaner create\u200b(ThreadFactory threadFactory)<\/font><\/strong><\/p>\n<p><font color=\"#666666\">ThreadFactory\u304b\u3089Thread\u3092\u4f7f\u7528\u3057\u3066\u65b0\u3057\u3044Cleaner\u3092\u8fd4\u3057\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u30b9\u30ec\u30c3\u30c9\u30fb\u30d5\u30a1\u30af\u30c8\u30ea\u306enewThread\u30e1\u30bd\u30c3\u30c9\u304b\u3089\u306e\u30b9\u30ec\u30c3\u30c9\u306fdaemon thread\u306b\u8a2d\u5b9a\u3055\u308c\u3001\u30d5\u30a1\u30f3\u30c8\u30e0\u5230\u9054\u53ef\u80fd\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u51e6\u7406\u3057\u3001\u30af\u30ea\u30fc\u30f3\u30fb\u30a2\u30af\u30b7\u30e7\u30f3\u3092\u8d77\u52d5\u3057\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u5404\u547c\u3073\u51fa\u3057\u3067\u3001thread factory\u306f\u3001\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u30fb\u30a2\u30af\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3059\u308b\u306e\u306b\u9069\u3057\u305f\u30b9\u30ec\u30c3\u30c9\u3092\u63d0\u4f9b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u30d5\u30a1\u30f3\u30c8\u30e0\u306b\u5230\u9054\u3057\u3001\u767b\u9332\u3055\u308c\u305f\u3059\u3079\u3066\u306e\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u52d5\u4f5c\u304c\u5b8c\u4e86\u3059\u308b\u3068\u3001\u30af\u30ea\u30fc\u30ca\u306f\u7d42\u4e86\u3057\u307e\u3059\u3002<\/font><\/p>\n<p><font color=\"#666666\">\u30d1\u30e9\u30e1\u30fc\u30bf:threadFactory &#8211; \u65b0\u3057\u3044Thread\u3092\u8fd4\u3057\u3066\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u30fb\u30a2\u30af\u30b7\u30e7\u30f3\u3092\u51e6\u7406\u3059\u308bThreadFactory<\/font><\/p>\n<p><font color=\"#666666\">\u623b\u308a\u5024:\u65b0\u3057\u3044Cleaner\u4f8b\u5916:IllegalThreadStateException &#8211; \u30b9\u30ec\u30c3\u30c9\u30fb\u30d5\u30a1\u30af\u30c8\u30ea\u304b\u3089\u306e\u30b9\u30ec\u30c3\u30c9\u304cnot a new thread\u306e\u5834\u5408\u3002<br \/>SecurityException &#8211; \u73fe\u5728\u306e\u30b9\u30ec\u30c3\u30c9\u304c\u30b9\u30ec\u30c3\u30c9\u306e\u4f5c\u6210\u307e\u305f\u306f\u958b\u59cb\u3092\u8a31\u53ef\u3055\u308c\u3066\u3044\u306a\u3044\u5834\u5408\u3002<\/font><\/p>\n<p><strong><font size=\"3\">public Cleaner.Cleanable register\u200b(Object obj, Runnable action)<\/font><\/strong><\/p>\n<p><font color=\"#666666\">\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u30d5\u30a1\u30f3\u30c8\u30e0\u5230\u9054\u53ef\u80fd\u306b\u306a\u3063\u305f\u3068\u304d\u306b\u5b9f\u884c\u3059\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u30fb\u30a2\u30af\u30b7\u30e7\u30f3\u3092\u767b\u9332\u3057\u307e\u3059\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u52d5\u4f5c\u306e\u52d5\u4f5c\u306b\u3064\u3044\u3066\u306f\u3001\u4e0a\u8a18\u306e\u300cAPI\u30ce\u30fc\u30c8\u300d\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002 <\/font><\/p>\n<p><font color=\"#666666\">\u30d1\u30e9\u30e1\u30fc\u30bf:obj &#8211; \u76e3\u8996\u3059\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<br \/>action &#8211; \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u30d5\u30a1\u30f3\u30c8\u30e0\u5230\u9054\u53ef\u80fd\u306b\u306a\u3063\u305f\u3068\u304d\u306b\u547c\u3073\u51fa\u3059Runnable<\/font><\/p>\n<p><font color=\"#666666\">\u623b\u308a\u5024:Cleanable\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9<\/font><\/p>\n<p>\u3053\u308c\u3067\u4eca\u5ea6\u3053\u305d PhantomReference \u3092\u4f7f\u3046\u70ba\u306e\u5fc5\u8981\u6700\u5c0f\u9650\u306e\u60c5\u5831\u3092\u3056\u3063\u304f\u308a\u3068 API \u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u304b\u3089\u5b66\u3093\u3060\u3002<\/p>\n<p>\u7c21\u5358\u306b PhantomReference \u3063\u3066\u3051\u3063\u304d\u3087\u304f\u3069\u3046\u306a\u306e\uff1f\u3063\u3066\u306e\u3092\u8003\u3048\u3066\u307f\u308b\u3068<\/p>\n<p>\u30d5\u30a1\u30f3\u30c8\u30e0\u5230\u9054\u53ef\u80fd\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092 ReferenceQueue \u306b\u5165\u308c\u308b\u3002<\/p>\n<p><strong>\u6ce8\u610f:) \u30d5\u30a1\u30f3\u30c8\u30e0\u5230\u9054\u53ef\u80fd\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e ReferenceQueue \u3078\u306e\u633f\u5165\u306f\u30ac\u30fc\u30d9\u30b8\u30fb\u30b3\u30ec\u30af\u30c8\u3068\u975e\u540c\u671f\u3067\u884c\u308f\u308c\u307e\u3059\u3002\u3088\u3063\u3066 GC \u304c\u50cd\u3044\u3066\u3059\u3050\u306b\u633f\u5165\u3055\u308c\u308b\u3068\u8003\u3048\u3066\u306f\u3044\u3051\u306a\u3044\u3088\u3046\u3067\u3059\u3002<\/strong><\/p>\n<p>Reference&lt;T&gt; \u30af\u30e9\u30b9\u306e\u4e09\u3064\u3042\u308b\u30e1\u30bd\u30c3\u30c9 poll()\u3001remove()\u3001remove\u200b(long timeout) \u306e\u4f55\u308c\u304b\u306b\u3088\u3063\u3066 ReferenceQueue \u306b\u5165\u308c\u3089\u308c\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u53d6\u308a\u51fa\u3057\u3066\u30af\u30ea\u30fc\u30f3\u30a2\u30c3\u30d7\u3059\u308b\u3002<\/p>\n<p>\u3053\u308c\u3068\u306f\u5225\u306b finalize() \u304b Cleaner \u30af\u30e9\u30b9\u3092\u4f7f\u3063\u3066\u30af\u30ea\u30fc\u30f3\u30a2\u30c3\u30d7\u3059\u308b\u65b9\u6cd5\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u30af\u30ea\u30fc\u30f3\u30a2\u30c3\u30d7\u306e\u969b\u306f\u30ea\u30bd\u30fc\u30b9\u306e\u89e3\u653e\u51e6\u7406\u304c\u5fc5\u8981\u3067\u3042\u308c\u3070\u5fc5\u305a\u5b9f\u884c\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u304a\u304f\u306e\u304c\u7121\u96e3\u304b\u3082\u3057\u308c\u306a\u3044\u3002<\/p>\n<p>\u6b63\u3057\u304f\u7406\u89e3\u3067\u304d\u3066\u3044\u308b\u304b\u306f\u602a\u3057\u3044\u3051\u3069\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u7d44\u3093\u3067\u307f\u308b\u3053\u3068\u306b\u3059\u308b\u3002<\/p>\n<p>\u3068\u308a\u3042\u3048\u305a\u3001\u524d\u56de\u3001\u524d\u3005\u56de\u306b\u7d44\u3093\u3060 SoftReference \u3068 WeakReference \u306e PhantomReference \u30d0\u30fc\u30b8\u30e7\u30f3\u3068\u3057\u3066\u307f\u3088\u3046\u3002<\/p>\n<p>\u307e\u305a\u3001JDK 1.8 \u5bfe\u5fdc\u306e\u3082\u306e\u304b\u3089\u7d44\u3093\u3067\u3001\u6700\u65b0\u306e JDK 11 \u3067\u4f7f\u3048\u308b Cleaner \u30af\u30e9\u30b9\u3092\u4f7f\u3063\u305f\u3082\u306e\u306b\u5909\u66f4\u3057\u3066\u307f\u308b\u3002<\/p>\n<p>\u305d\u3093\u306a\u3053\u3093\u306a\u3067\u6b21\u306e\u3088\u3046\u306a\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u7d44\u3093\u3067\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>&nbsp;<\/p>\n<pre title=\"PhantomExterminationClassic.java\"><code>\r\npackage jp.yucchi.phantomexterminationclassic;\r\n\r\nimport java.lang.management.GarbageCollectorMXBean;\r\nimport java.lang.management.ManagementFactory;\r\nimport java.lang.management.MemoryMXBean;\r\nimport java.lang.management.MemoryUsage;\r\nimport java.lang.ref.PhantomReference;\r\nimport java.lang.ref.Reference;\r\nimport java.lang.ref.ReferenceQueue;\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 PhantomExterminationClassic {\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\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;PhantomReference&lt;MemoryConsumer&gt;&gt; list = new ArrayList&lt;&gt;();\r\n\r\n        for (int i = 0; i &lt; 1_000; i++) {\r\n            MemoryConsumer memoryConsumer = new MemoryConsumer();\r\n            PhantomReference&lt;MemoryConsumer&gt; phantomReference = new PhantomReference&lt;&gt;(memoryConsumer, REFEREN_CEQUEU);\r\n            list.add(phantomReference);\r\n            checkStatus();\r\n        }\r\n    }\r\n\r\n    private static void checkStatus() {\r\n\r\n        MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();\r\n        MemoryUsage usage = memoryBean.getHeapMemoryUsage();\r\n        long usedMemory = usage.getUsed();\r\n        List&lt;GarbageCollectorMXBean&gt; gcMXBeans = ManagementFactory.getGarbageCollectorMXBeans();\r\n        StringBuilder 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\/\/            if (Double.parseDouble(System.getProperty(\"java.specification.version\")) &lt; 1.9) {\r\n\/\/                ref.clear();\r\n\/\/            }\r\n\/\/        }\r\n\r\n    }\r\n\r\n    private static class MemoryConsumer {\r\n\r\n        private 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            this.buff = null;\r\n        }\r\n\r\n    }\r\n\r\n}\r\n\r\n<\/code><\/pre>\n<p>\u3053\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u306f finalize() \u30e1\u30bd\u30c3\u30c9\u3092\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3057\u3066\u5229\u7528\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>finalize() \u30e1\u30bd\u30c3\u30c9\u5185\u3067 this.buff = null; \u3068\u3057\u3066 OutOfMemoryError \u3092\u56de\u907f\u3057\u3066\u3044\u307e\u3059\u3002\uff08\u3053\u306e\u3088\u3046\u306a\u3053\u3068\u306f JDK 11 \u3067\u306f\u5fc5\u8981\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002\uff09<\/p>\n<p>Reference&lt;T&gt; \u30af\u30e9\u30b9\u306e poll() \u30e1\u30bd\u30c3\u30c9\u306f\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u3057\u3066\u5b9f\u884c\u3067\u304d\u306a\u3044\u3088\u3046\u306b\u3057\u3066\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b finalize() \u30e1\u30bd\u30c3\u30c9\u3082\u4f7f\u308f\u306a\u3051\u308c\u3070 OutOfMemoryError \u3067\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u9014\u4e2d\u3067\u6b62\u307e\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u5b9f\u884c\u7d50\u679c\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><font color=\"#666666\">Windows 10 10.0 amd64<br \/>JDK 1.8.0_144<\/font><\/p>\n<p><font color=\"#666666\">UsedMemory: 115595064&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 241927592&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&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 \/>UsedMemory: 321118712&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 1&nbsp;&nbsp; GCTime = 128&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 430987664&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 1&nbsp;&nbsp; GCTime = 128&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&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 \/>UsedMemory: 525473600&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 2&nbsp;&nbsp; GCTime = 257&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0<br \/>\u7565<br \/>UsedMemory: 6299540808&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 26&nbsp;&nbsp; GCTime = 30760&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 24&nbsp;&nbsp; GCTime = 6659&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 6404398424&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 26&nbsp;&nbsp; GCTime = 30760&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 24&nbsp;&nbsp; GCTime = 6659&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 6509256040&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 26&nbsp;&nbsp; GCTime = 30760&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 24&nbsp;&nbsp; GCTime = 6659&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 6614113656&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 26&nbsp;&nbsp; GCTime = 30760&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 24&nbsp;&nbsp; GCTime = 6659<\/font><\/p>\n<p>57\u79d2\u307b\u3069\u3067\u7d42\u4e86\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u3061\u3087\u3063\u3068\u9045\u3044\u3067\u3059\u306d\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\/11.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"11\" 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=\"11\" src=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/11_thumb.png\" width=\"904\" height=\"447\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/12.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"12\" 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=\"12\" src=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/12_thumb.png\" width=\"904\" height=\"450\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/13.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"13\" 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=\"13\" src=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/13_thumb.png\" width=\"904\" height=\"454\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>JDK 1.8 \u306e\u6a19\u6e96\u306e\u30ac\u30fc\u30d9\u30b8\u30fb\u30b3\u30ec\u30af\u30bf\u3063\u3066\u3053\u3093\u306a\u3082\u306e\u306a\u306e\u304b\uff1f<\/p>\n<p>\u305d\u308c\u3067\u306f\u5148\u307b\u3069\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092 Reference&lt;T&gt; \u30af\u30e9\u30b9\u306e poll() \u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046\u3088\u3046\u306b\u5909\u66f4\u3057\u305f\u5b9f\u884c\u7d50\u679c\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p><font color=\"#666666\">Windows 10 10.0 amd64<br \/>JDK 1.8.0_144<\/font><\/p>\n<p><font color=\"#666666\">UsedMemory: 115595064&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 241927592&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 315733616&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 1&nbsp;&nbsp; GCTime = 129&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp; &#8212; POLL:java.lang.ref.PhantomReference@548c4f57 &#8212;<br \/>&nbsp;&nbsp;&nbsp; &#8212; POLL:java.lang.ref.PhantomReference@1218025c &#8212;<br \/>UsedMemory: 425602568&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 1&nbsp;&nbsp; GCTime = 129&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 525440640&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 2&nbsp;&nbsp; GCTime = 260&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp; &#8212; POLL:java.lang.ref.PhantomReference@816f27d &#8212;<br \/>&nbsp;&nbsp;&nbsp; &#8212; POLL:java.lang.ref.PhantomReference@87aac27 &#8212;<br \/>UsedMemory: 640519896&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 2&nbsp;&nbsp; GCTime = 260&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 745377512&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 2&nbsp;&nbsp; GCTime = 260&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 850235128&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 2&nbsp;&nbsp; GCTime = 260&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 955092744&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 2&nbsp;&nbsp; GCTime = 260&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 629860128&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 3&nbsp;&nbsp; GCTime = 569&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 1&nbsp;&nbsp; GCTime = 43&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp; &#8212; POLL:java.lang.ref.PhantomReference@3e3abc88 &#8212;<br \/>\u7565<br \/>&nbsp;&nbsp;&nbsp; &#8212; POLL:java.lang.ref.PhantomReference@cb644e &#8212;<br \/>UsedMemory: 5880074344&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 26&nbsp;&nbsp; GCTime = 30258&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 24&nbsp;&nbsp; GCTime = 6566&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 5984931960&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 26&nbsp;&nbsp; GCTime = 30258&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 24&nbsp;&nbsp; GCTime = 6566&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 6089789576&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 26&nbsp;&nbsp; GCTime = 30258&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 24&nbsp;&nbsp; GCTime = 6566&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 6194647192&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 26&nbsp;&nbsp; GCTime = 30258&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 24&nbsp;&nbsp; GCTime = 6566&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 6299504808&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 26&nbsp;&nbsp; GCTime = 30258&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 24&nbsp;&nbsp; GCTime = 6566&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 6404362424&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 26&nbsp;&nbsp; GCTime = 30258&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 24&nbsp;&nbsp; GCTime = 6566&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 6509220040&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 26&nbsp;&nbsp; GCTime = 30258&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 24&nbsp;&nbsp; GCTime = 6566&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 6614077656&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 26&nbsp;&nbsp; GCTime = 30258&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 24&nbsp;&nbsp; GCTime = 6566&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 6718935272&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 26&nbsp;&nbsp; GCTime = 30258&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 24&nbsp;&nbsp; GCTime = 6566&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 6823792888&nbsp;&nbsp; PS Scavenge&nbsp;&nbsp; GC Count: 26&nbsp;&nbsp; GCTime = 30258&nbsp;&nbsp;&nbsp;&nbsp; PS MarkSweep&nbsp;&nbsp; GC Count: 24&nbsp;&nbsp; GCTime = 6566<\/font><\/p>\n<p>56\u79d2\u3067\u7d42\u4e86\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>finalize() \u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u305f\u306e\u3068\u307b\u307c\u540c\u3058\u3067\u3059\u306d\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b64\u884c\u76ee\u306e ref.clear() \u30e1\u30bd\u30c3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u30af\u30ea\u30a2\u3057\u306a\u3044\u3068 OutOfMemoryError \u3067\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u9014\u4e2d\u3067\u6b62\u307e\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<p>JDK 11 \u3067\u306f clear() \u30e1\u30bd\u30c3\u30c9\u3067\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u30af\u30ea\u30a2\u3057\u306a\u304f\u3066\u3082OutOfMemoryError \u3067\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u6b62\u307e\u308b\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u3044\u3061\u304a\u3046 NetBeans \u306e\u30d7\u30ed\u30d5\u30a1\u30a4\u30e9\u3067\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/14.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"14\" 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=\"14\" src=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/14_thumb.png\" width=\"904\" height=\"476\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/15.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"15\" 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=\"15\" src=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/15_thumb.png\" width=\"904\" height=\"473\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/16.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"16\" 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=\"16\" src=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/16_thumb.png\" width=\"904\" height=\"484\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>\u5927\u304d\u306a\u9055\u3044\u306f\u306a\u3055\u305d\u3046\u3067\u3059\u3002<\/p>\n<p>\u305d\u308c\u3067\u306f JDK 11 \u306b\u5207\u308a\u66ff\u3048\u3066 finalize() \u30e1\u30bd\u30c3\u30c9 \u3092\u5229\u7528\u3057\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>JDK 1.8 \u3068\u306e\u6bd4\u8f03\u306e\u305f\u3081\u306b\u3042\u3048\u3066 finalize() \u30e1\u30bd\u30c3\u30c9 \u3092\u4f7f\u3063\u3066\u307e\u3059\u3002\u3042\u3068\u3067 Cleaner \u30af\u30e9\u30b9\u3092\u4f7f\u3063\u305f\u3082\u306e\u3082\u8a66\u3057\u3066\u307f\u307e\u3059\u3002<\/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><font color=\"#666666\">Windows 10 10.0 amd64<br \/>JDK 11.0.1<\/font><\/p>\n<p><font color=\"#666666\">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: 546494784&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 \/>UsedMemory: 655546688&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; finalize &#8212;<br \/>&nbsp;&nbsp;&nbsp; &#8212; finalize &#8212;<br \/>UsedMemory: 328435288&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 2&nbsp;&nbsp; GCTime = 7&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 437487192&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 2&nbsp;&nbsp; GCTime = 7&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>\u7565<br \/><\/font><\/p>\n<p><font color=\"#666666\">&nbsp;&nbsp;&nbsp; &#8212; finalize &#8212;<br \/>&nbsp;&nbsp;&nbsp; &#8212; finalize &#8212;<br \/>&nbsp;&nbsp;&nbsp; &#8212; finalize &#8212;<br \/>UsedMemory: 2073652944&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 106&nbsp;&nbsp; GCTime = 244&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 2182704848&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 106&nbsp;&nbsp; GCTime = 244&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 2291756752&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 106&nbsp;&nbsp; GCTime = 244&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0<\/font> <\/p>\n<p>15\u79d2\u3067\u7d42\u4e86\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>JDK 11 \u306e\u30ac\u30fc\u30d9\u30b8\u30fb\u30b3\u30ec\u30af\u30bf\u512a\u79c0\u3067\u3059\u306d\u3002<\/p>\n<p>\u78ba\u304b JDK 9 \u304b\u3089 G1GC \u304c\u6a19\u6e96\u306b\u306a\u3063\u305f\u306f\u305a\u3002<\/p>\n<p>\u3053\u308c\u3082 NetBeans \u306e\u30d7\u30ed\u30d5\u30a1\u30a4\u30e9\u3067\u8997\u3044\u3066\u307f\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/17.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"17\" 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=\"17\" src=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/17_thumb.png\" width=\"597\" height=\"570\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/18.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"18\" 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=\"18\" src=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/18_thumb.png\" width=\"617\" height=\"557\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/19.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"19\" 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=\"19\" src=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/19_thumb.png\" width=\"583\" height=\"581\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>\u3053\u306e\u9055\u3044\u3092\u76ee\u306e\u5f53\u305f\u308a\u306b\u3059\u308b\u3068 JDK 1.8 \u306f\u3082\u3046\u4f7f\u3048\u306a\u3044\u3002(^_^;)<\/p>\n<p>\u3067\u306f\u3001Reference&lt;T&gt; \u30af\u30e9\u30b9\u306e poll() \u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046\u3088\u3046\u306b\u5909\u66f4\u3057\u3066\u5b9f\u884c\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u5b9f\u884c\u7d50\u679c\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><font color=\"#666666\">Windows 10 10.0 amd64<br \/>JDK 11.0.1<\/font><\/p>\n<p><font color=\"#666666\">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 \/>UsedMemory: 110281288&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.PhantomReference@d8355a8 &#8212;<br \/>&nbsp;&nbsp;&nbsp; &#8212; POLL:java.lang.ref.PhantomReference@5e5792a0 &#8212;<br \/>&nbsp;&nbsp;&nbsp; &#8212; POLL:java.lang.ref.PhantomReference@26653222 &#8212;<br \/>&nbsp;&nbsp;&nbsp; &#8212; POLL:java.lang.ref.PhantomReference@3532ec19 &#8212;<br \/>UsedMemory: 219333192&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 \/>UsedMemory: 328385096&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 \/>UsedMemory: 437437000&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 \/>UsedMemory: 110345216&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 2&nbsp;&nbsp; GCTime = 7&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.PhantomReference@68c4039c &#8212;<br \/>\u7565<br \/>&nbsp;&nbsp;&nbsp; &#8212; POLL:java.lang.ref.PhantomReference@5db250b4 &#8212;<br \/>&nbsp;&nbsp;&nbsp; &#8212; POLL:java.lang.ref.PhantomReference@223f3642 &#8212;<br \/>UsedMemory: 219733600&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 99&nbsp;&nbsp; GCTime = 208&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0<\/font><\/p>\n<p>\u3053\u308c\u308215\u79d2\u3067\u7d42\u4e86\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>NetBeans \u306e\u30d7\u30ed\u30d5\u30a1\u30a4\u30e9\u3067\u8997\u3044\u3066\u307f\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/20.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"20\" 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=\"20\" src=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/20_thumb.png\" width=\"490\" height=\"570\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/21.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"21\" 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=\"21\" src=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/21_thumb.png\" width=\"496\" height=\"573\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/22.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"22\" 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=\"22\" src=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/22_thumb.png\" width=\"479\" height=\"571\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>\u3053\u3061\u3089\u306e\u307b\u3046\u304c\u50c5\u304b\u3060\u3051\u3069\u826f\u3044\u304b\u3082\u3057\u308c\u306a\u3044\u3002<\/p>\n<p>JDK 1.8 \u3068 JDK 11 \u306e\u9055\u3044\u306f\u30ac\u30fc\u30d9\u30b8\u30fb\u30b3\u30ec\u30af\u30bf\u304c\u5909\u66f4\u3055\u308c\u305f\u304f\u3089\u3044\u3060\u3068\u601d\u3046\u306e\u3067\u3059\u3051\u3069\u4ed6\u306b\u3082\u4f55\u304b\u5909\u66f4\u304c\u3042\u308b\u306e\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>\u3061\u3087\u3063\u3068\u6c17\u306b\u306a\u308b\u306e\u3067 JDK 1.8 \u3068 JDK 11 \u306e\u30b9\u30ec\u30c3\u30c9\u3092\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>\u4e21\u65b9\u3068\u3082 Reference&lt;T&gt; \u30af\u30e9\u30b9\u306e poll() \u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u305f\u5834\u5408\u3067\u3059\u3002<\/p>\n<p>\u307e\u305a\u3001JDK 1.8 \u304b\u3089<\/p>\n<p><a href=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/23.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"23\" 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=\"23\" src=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/23_thumb.png\" width=\"904\" height=\"190\"><\/a><\/p>\n<p>\u6b21\u306f JDK 11\u3067\u3059\u3002<\/p>\n<p><a href=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/24.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"24\" 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=\"24\" src=\"http:\/\/yucchi.jp\/blog\/wp-content\/uploads\/2019\/01\/24_thumb.png\" width=\"904\" height=\"187\"><\/a><\/p>\n<p>JDK 11 \u306e\u307b\u3046\u306b Common-Cleaner \u3068\u3044\u3046\u898b\u6163\u308c\u306a\u3044\u30b9\u30ec\u30c3\u30c9\u304c\u3042\u308a\u307e\u3059\u306d\u3002<\/p>\n<p>\u3053\u308c\u304c\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u30a2\u30c3\u30d7\u306e\u8981\u56e0\u306e\u4e00\u3064\u306a\u306e\u304b\u306a\u3002<\/p>\n<p>GC \u95a2\u9023\u306e\u3053\u3068\u306f\u3042\u307e\u308a\u6c17\u306b\u3057\u305f\u3053\u3068\u306a\u3044\u306e\u3067\u3088\u304f\u89e3\u308a\u307e\u305b\u3093\u3002(&gt;_&lt;\uff61)<\/p>\n<p>\u540d\u524d\u304b\u3089\u3057\u3066\u52dd\u624b\u306b\u30af\u30ea\u30fc\u30f3\u30a2\u30c3\u30d7\u3057\u3066\u304f\u308c\u305d\u3046\u306a\u306e\u3067 finalize() \u30e1\u30bd\u30c3\u30c9\u3001Reference&lt;T&gt; \u30af\u30e9\u30b9\u306e poll() \u30e1\u30bd\u30c3\u30c9\u4e21\u65b9\u3068\u3082\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u3057\u3066\u7121\u52b9\u306b\u3057\u3066\u5b9f\u884c\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>OutOfMemoryError \u3067\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u6b62\u307e\u308a\u307e\u3057\u30fb\u30fb\u30fb\u3000\u3000\u3042\u308c\u3063\uff01\u3000\u6b62\u307e\u3089\u306a\u3044\u3002<\/p>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u306f15\u79d2\u3067\u7d42\u4e86\u3057\u307e\u3057\u305f\u3002<\/p>\n<p><font color=\"#666666\">Windows 10 10.0 amd64<br \/>JDK 11.0.1<\/font><\/p>\n<p><font color=\"#666666\">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 \/>UsedMemory: 110281920&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 \/>UsedMemory: 219333824&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 \/>UsedMemory: 328385728&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 \/>UsedMemory: 437437632&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 \/>UsedMemory: 110325528&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 \/><\/font><\/p>\n<p><font color=\"#666666\">UsedMemory: 1092084152&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 98&nbsp;&nbsp; GCTime = 200&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 1201136056&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 98&nbsp;&nbsp; GCTime = 200&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 110617168&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 99&nbsp;&nbsp; GCTime = 202&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 219669072&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 99&nbsp;&nbsp; GCTime = 202&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>BUILD SUCCESSFUL (total time: 15 seconds)<\/font><\/p>\n<p>\u3044\u3063\u305f\u3044\u3069\u3046\u3044\u3046\u3053\u3068\u306a\u3093\u3060\uff1f<\/p>\n<p>\u30af\u30ea\u30fc\u30f3\u30a2\u30c3\u30d7\u306e\u969b\u306b\u30ea\u30bd\u30fc\u30b9\u306e\u89e3\u653e\u51e6\u7406\u304c\u5fc5\u8981\u3067\u7121\u3044\u306e\u306a\u3089\u4f55\u3082\u3057\u306a\u304f\u3066\u3082\u3044\u3044\u306e\u304b\uff1f<\/p>\n<p>JDK 1.8 \u3067 Reference&lt;T&gt; \u30af\u30e9\u30b9\u306e poll() \u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046\u5834\u5408\u306f clear() \u30e1\u30bd\u30c3\u30c9\u3067\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u30af\u30ea\u30a2\u3057\u3066\u6b21\u306e GC \u3067\u89e3\u653e\u3055\u308c\u308b\u3068\u3044\u3046\u6700\u4f4e\u3067\u3082 GC \u304c\u4e8c\u56de\u5fc5\u8981\u3060\u3063\u305f\u306e\u306b\u30fb\u30fb\u30fb<\/p>\n<p>\u30ac\u30fc\u30d9\u30b8\u30fb\u30b3\u30ec\u30af\u30bf\u51c4\u304f\u8ce2\u304f\u306a\u3063\u3066\u3044\u308b\u3002\uff08\u79c1\u304c PhantomReference \u306e\u4f7f\u3044\u65b9\u3092\u9593\u9055\u3063\u3066\u308b\u304b\u3082\u3057\u308c\u306a\u3044\uff09<\/p>\n<p>\u3053\u306e\u3042\u305f\u308a\u306e\u3053\u3068\u3092\u8abf\u3079\u51fa\u3059\u3068\u30ac\u30fc\u30d9\u30b8\u30fb\u30b3\u30ec\u30af\u30bf\u6cbc\u306b\u306f\u307e\u3063\u3066\u82e6\u3057\u3080\u3053\u3068\u306b\u306a\u308b\u306e\u3067\u8ab0\u304b\u89aa\u5207\u306a\u4eba\u304c\u8a73\u3057\u304f\u89e3\u308a\u3084\u3059\u3044\u89e3\u8aac\u8a18\u4e8b\u3092\u30cd\u30c3\u30c8\u4e0a\u306b\u30a2\u30c3\u30d7\u3057\u3066\u304f\u308c\u308b\u306e\u3092\u5f85\u3064\u3053\u3068\u306b\u3059\u308b\u3002<\/p>\n<p>\u305d\u308c\u3067\u306f\u6700\u5f8c\u306b Cleaner \u30af\u30e9\u30b9 \u3092\u4f7f\u3063\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e Cleaner \u30af\u30e9\u30b9\u3082\u30d5\u30a1\u30a4\u30ca\u30e9\u30a4\u30b6\u540c\u69d8\u306b\u3042\u307e\u308a\u4f7f\u3046\u306e\u3092\u597d\u307e\u3057\u304f\u601d\u308f\u308c\u3066\u3044\u307e\u305b\u3093\u3002<\/p>\n<p>\u8a73\u7d30\u306f<strong>\u300cEffective Java \u7b2c\uff13\u7248\u300d\u306e\u7b2c\uff12\u7ae0\u3000\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u751f\u6210\u3068\u6d88\u6ec5\u3000\u9805\u76ee 8 \u30d5\u30a1\u30a4\u30ca\u30e9\u30a4\u30b6\u3068\u30af\u30ea\u30fc\u30ca\u30fc\u3092\u907f\u3051\u308b<\/strong>\u3000\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><iframe style=\"height: 240px; width: 120px\" marginheight=\"0\" src=\"\/\/rcm-fe.amazon-adsystem.com\/e\/cm?lt1=_blank&amp;bc1=000000&amp;IS2=1&amp;bg1=FFFFFF&amp;fc1=000000&amp;lc1=0000FF&amp;t=yucchi05-22&amp;language=ja_JP&amp;o=9&amp;p=8&amp;l=as4&amp;m=amazon&amp;f=ifr&amp;ref=as_ss_li_til&amp;asins=4621303252&amp;linkId=fd36622bb45ed67ed825ceaaf82c5701\" frameborder=\"0\" marginwidth=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<p>\u305d\u308c\u3067\u306f Cleaner \u30af\u30e9\u30b9\u3092\u4f7f\u3063\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u307e\u3067\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092 JDK 10 \u4ee5\u964d\u306e\u65b0\u3057\u3044\u3082\u306e\u3092\u4f7f\u3046\u3053\u3068\u3092\u524d\u63d0\u306b\u3057\u3066\u7d44\u307f\u76f4\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>&nbsp;<\/p>\n<pre title=\"PhantomExtermination.java\" mark=\"30,31\"><code>\r\npackage jp.yucchi.phantomextermination;\r\n\r\nimport java.lang.management.ManagementFactory;\r\nimport java.lang.ref.Cleaner;\r\nimport java.lang.ref.PhantomReference;\r\nimport java.lang.ref.Reference;\r\nimport java.lang.ref.ReferenceQueue;\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 PhantomExtermination {\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\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;PhantomReference&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 cleaner = Cleaner.create();\r\n            cleaner.register(memoryConsumer, new CleanerRunnable(memoryConsumer.buff, i));\r\n            var phantomReference = new PhantomReference&lt;&gt;(memoryConsumer, REFEREN_CEQUEU);\r\n            list.add(phantomReference);\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 CleanerRunnable implements Runnable {\r\n\r\n        private int ObjectNumber;\r\n        private byte[] buff;\r\n\r\n        CleanerRunnable(int ObjectNumber) {\r\n        }\r\n\r\n        private CleanerRunnable(byte[] buff, int ObjectNumber) {\r\n            this.ObjectNumber = ObjectNumber;\r\n            this.buff = buff;\r\n        }\r\n\r\n        @Override\r\n        public void run() {\r\n            System.out.println(\"Cleaning: \" + ObjectNumber++);\r\n            buff = null;\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    }\r\n<font face=\"\u30e1\u30a4\u30ea\u30aa\"><\/font>\r\n}\r\n\r\n<\/code><\/pre>\n<p>30\u884c\u76ee\u3067 Cleaner \u3092\u751f\u6210\u300131\u884c\u76ee\u3067\u30d5\u30a1\u30f3\u30c8\u30e0\u5230\u9054\u53ef\u80fd\u306b\u306a\u3063\u305f\u3068\u304d\u306b\u5b9f\u884c\u3059\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u30fb\u30a2\u30af\u30b7\u30e7\u30f3\u3092\u767b\u9332\u3057\u307e\u3059\u3002<\/p>\n<p><font color=\"#666666\">var cleaner = Cleaner.create();<br \/>cleaner.register(memoryConsumer, new CleanerRunnable(memoryConsumer.buff, i));<\/font><\/p>\n<p>\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u30fb\u30a2\u30af\u30b7\u30e7\u30f3\u306e\u767b\u9332\u3067<font color=\"#666666\">new CleanerRunnable(memoryConsumer.buff, i)<\/font> \u3068\u7121\u99c4\u306a\u3053\u3068\u3092\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u306f\u304a\u904a\u3073\u3067\u3059\u306e\u3067\u5f15\u6570\u7121\u3057\u3067\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u30fb\u30a2\u30af\u30b7\u30e7\u30f3\u306e run() \u30e1\u30bd\u30c3\u30c9\u5185\u306e\u30b4\u30cb\u30e7\u30b4\u30cb\u30e7\u3057\u305f\u30b3\u30fc\u30c9\u306f\u7121\u304f\u3066\u7a7a\u3067\u3082\u554f\u984c\u7121\u3044\u3067\u3059\u3002<\/p>\n<p>84\u884c\u76ee\u306e <font color=\"#666666\">buff = null;<\/font> \u3082\u3042\u3063\u3066\u3082\u7121\u304f\u3066\u3082\u307b\u307c\u5909\u308f\u308a\u306f\u3042\u308a\u307e\u305b\u3093\u3002\uff08\u5c11\u3057\u306f\u5909\u308f\u308b\u304b\u3082\u3068\u601d\u3063\u3066\u8a66\u3057\u305f\u3060\u3051\u3067\u3059\uff09<\/p>\n<p>\u305f\u3063\u305f\u3053\u308c\u3060\u3051\u3067\u3059\uff01\u975e\u5e38\u306b\u4fbf\u5229\u3067\u3059\u3002<\/p>\n<p>\u3053\u308c\u3067\u30d5\u30a1\u30a4\u30ca\u30e9\u30a4\u30b6\u653b\u6483\u306e\u5fc3\u914d\u306f\u306a\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u5b9f\u884c\u7d50\u679c\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><font color=\"#666666\">Windows 10 10.0 amd64<br \/>JDK 11.0.1<\/font><\/p>\n<p><font color=\"#666666\">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 \/>UsedMemory: 554883024&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 \/>UsedMemory: 663934928&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 \/>UsedMemory: 772986832&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 \/>UsedMemory: 882038736&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 \/>UsedMemory: 991090640&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 \/>UsedMemory: 1096034664&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 2&nbsp;&nbsp; GCTime = 5&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 1205086568&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 2&nbsp;&nbsp; GCTime = 5&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 1314138472&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 2&nbsp;&nbsp; GCTime = 5&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 1419045944&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 3&nbsp;&nbsp; GCTime = 8&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 1532292152&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 3&nbsp;&nbsp; GCTime = 8&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>Cleaning: 6<br \/>Cleaning: 1<br \/>Cleaning: 5<br \/>Cleaning: 3<br \/>Cleaning: 7<br \/>Cleaning: 0<br \/>Cleaning: 2<br \/>Cleaning: 4<br \/>Cleaning: 9<br \/>UsedMemory: 1645538360&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 3&nbsp;&nbsp; GCTime = 8&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>Cleaning: 11<br \/>Cleaning: 10<br \/>Cleaning: 8<br \/>UsedMemory: 1754590264&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 3&nbsp;&nbsp; GCTime = 8&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 1863642168&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 3&nbsp;&nbsp; GCTime = 8&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>Cleaning: 16<br \/>Cleaning: 15<br \/>Cleaning: 13<br \/>Cleaning: 14<br \/>Cleaning: 12<br \/>UsedMemory: 655688552&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 4&nbsp;&nbsp; GCTime = 12&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 764740456&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 4&nbsp;&nbsp; GCTime = 12&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 873792360&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 4&nbsp;&nbsp; GCTime = 12&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>Cleaning: 19<br \/>Cleaning: 17<br \/>Cleaning: 18<br \/>UsedMemory: 437556936&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 5&nbsp;&nbsp; GCTime = 15&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 546608840&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 5&nbsp;&nbsp; GCTime = 15&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 655660744&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 5&nbsp;&nbsp; GCTime = 15&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 764712648&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 5&nbsp;&nbsp; GCTime = 15&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 873764552&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 5&nbsp;&nbsp; GCTime = 15&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>Cleaning: 20<br \/>Cleaning: 21<br \/>Cleaning: 24<br \/>\u7565<br \/>UsedMemory: 1314754576&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 170&nbsp;&nbsp; GCTime = 285&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>Cleaning: 993<br \/>Cleaning: 992<br \/>Cleaning: 997<br \/>Cleaning: 995<br \/>Cleaning: 996<br \/>Cleaning: 991<br \/>Cleaning: 994<br \/>UsedMemory: 882748320&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 171&nbsp;&nbsp; GCTime = 287&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0&nbsp;&nbsp;&nbsp;&nbsp; <br \/>UsedMemory: 991800224&nbsp;&nbsp; G1 Young Generation&nbsp;&nbsp; GC Count: 171&nbsp;&nbsp; GCTime = 287&nbsp;&nbsp;&nbsp;&nbsp; G1 Old Generation&nbsp;&nbsp; GC Count: 0&nbsp;&nbsp; GCTime = 0<\/font> <\/p>\n<p>16\u79d2\u3067\u7d42\u4e86\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>Cleaner \u30af\u30e9\u30b9\u4f7f\u3046\u3068\u4fbf\u5229\u3067\u3059\u306d\u3002<\/p>\n<p>\u30d5\u30a1\u30f3\u30c8\u30e0\u5230\u9054\u53ef\u80fd\u306b\u306a\u3063\u305f\u3068\u304d\u306b\u5b9f\u884c\u3059\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u30fb\u30a2\u30af\u30b7\u30e7\u30f3\u3092\u767b\u9332\u3059\u308b\u3060\u3051\u3060\u3057\u3001\u305d\u308c\u306b\u30af\u30ea\u30fc\u30cb\u30f3\u30b0\u30fb\u30a2\u30af\u30b7\u30e7\u30f3\u7528\u306e\u5c02\u7528\u30b9\u30ec\u30c3\u30c9\u304c\u8d77\u52d5\u3055\u308c\u308b\u3002<\/p>\n<p>\u30d5\u30a1\u30a4\u30ca\u30e9\u30a4\u30b6\u3092\u4f7f\u3063\u3066\u4f55\u304b\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u81ea\u524d\u3067\u30b9\u30ec\u30c3\u30c9\u3092\u7528\u610f\u3057\u305f\u308a\u3057\u306a\u304f\u3061\u3083\u3044\u3051\u306a\u3044\u5834\u5408\u304c\u3042\u308b\u3002<\/p>\n<p>\u30d5\u30a1\u30a4\u30ca\u30e9\u30a4\u30b6\u653b\u6483\u306b\u3088\u308b\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u4e0a\u306e\u554f\u984c\u3082\u7121\u3044\u3002<\/p>\n<p>\u3082\u3046\u3001\u30d5\u30a1\u30a4\u30ca\u30e9\u30a4\u30b6\u3092\u4f7f\u3046\u5fc5\u8981\u306f\u7121\u3044\u3088\u3046\u306a\u6c17\u304c\u3059\u308b\u3002<\/p>\n<p>\u3069\u306e\u307f\u3061\u8fd1\u3044\u5c06\u6765\u4f7f\u3048\u306a\u304f\u306a\u308b\u3057\u306d\u3002<\/p>\n<p>\u30d1\u30c3\u30b1\u30fc\u30b8 java.lang.ref \u3092\u826f\u304f\u89e3\u3089\u306a\u3044\u307e\u307e\u3044\u308d\u3044\u308d\u3084\u3063\u3066\u307f\u305f\u3051\u3069 PhantomReference \u3063\u3066\u6271\u3044\u304c\u96e3\u3057\u3044\u3067\u3059\u306d\u3002<\/p>\n<p>\u305d\u3082\u305d\u3082\u30d5\u30a1\u30f3\u30c8\u30e0\u5230\u9054\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3063\u3066\u5f37\u53c2\u7167\u3001\u30bd\u30d5\u30c8\u53c2\u7167\u3001\u5f31\u53c2\u7167\u306e\u3069\u308c\u304b\u3089\u8fbf\u3063\u3066\u3082\u5230\u9054\u3067\u304d\u306a\u304f\u306a\u3063\u3066\u30d5\u30a1\u30a4\u30ca\u30e9\u30a4\u30b6\u547c\u3073\u51fa\u3057\u304c\u5b8c\u4e86\u3057\u305f\u72b6\u614b\u3063\u3066\u3068\u3053\u308d\u3067\u4f7f\u3044\u3069\u3053\u308d\u304c\u9650\u5b9a\u3055\u308c\u305d\u3046\u306a\u6c17\u304c\u3059\u308b\u3002<\/p>\n<p>ReferenceQueue \u306b\u5165\u308c\u3089\u308c\u305f PhantomReference \u306e get() \u30e1\u30bd\u30c3\u30c9\u306f null \u3092\u5e38\u6642\u8fd4\u3059\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u308b\u3002<\/p>\n<p>\u3064\u307e\u308a\u3001\u3053\u308c\u3063\u3066 GC \u5bfe\u8c61\u3063\u3066\u3053\u3068\u3067\u3059\u3088\u306d\u3002<\/p>\n<p>\u3060\u3081\u3060\u3001\u982d\u75db\u304c\u75db\u304f\u306a\u308a\u305d\u3046\u3060\u3002\uff08\u307e\u3055\u306b\u4eca\u3053\u3093\u306a\u611f\u3058\u3067\u3059\u3002\uff09<\/p>\n<p>PhantomReference \u3063\u3066\u305f\u3060\u306e\u30af\u30ea\u30fc\u30f3\u30a2\u30c3\u30d7\u7528\u306b\u3057\u304b\u601d\u3048\u306a\u304f\u306a\u3063\u3066\u304d\u305f\u3002(^_^;)<\/p>\n<p>\u3057\u304b\u3082\u3001JDK 1.8 \u306e\u9803\u306e\u307b\u3046\u304c\u4e0d\u601d\u8b70\u306a\u52d5\u4f5c\u3092\u305b\u305a\u7406\u89e3\u3057\u3084\u3059\u3044\u3051\u3069 JDK 11 \u3068\u306e\u9055\u3044\u306f\u5927\u304d\u3059\u304e\u308b\u3002<\/p>\n<p>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u30a2\u30c3\u30d7\u3084\u4f7f\u3044\u52dd\u624b\u304c\u826f\u304f\u306a\u308b\u306e\u306f\u3044\u3044\u3051\u3069\u89e3\u308a\u3084\u3059\u3044\u60c5\u5831\u304c\u4e4f\u3057\u3044\u306e\u306f\u306a\u3093\u3068\u304b\u3057\u3066\u307b\u3057\u3044\u3002<\/p>\n<p>\u4eca\u65e5\u3067\u304a\u6b63\u6708\u4f11\u307f\u3082\u7d42\u308f\u3063\u3066\u3057\u307e\u3046\u3051\u3069\u3082\u3063\u3068 Java \u3092\u697d\u3057\u3081\u308b\u4e00\u5e74\u306b\u306a\u308b\u3088\u3046\u306b\u304c\u3093\u3070\u308b\u305e\u3044\uff01<\/p>\n<div id=\"scid:0767317B-992E-4b12-91E0-4F059A8CECA8:c223ca68-802f-4fb1-b4e9-05e3380a0d7a\" 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%3D2714&title=PhantomReference' 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%3D2714&t=PhantomReference' 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=2714\" ><\/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=2714\" data-text=\"PhantomReference\" data-lang=\"ja\">Tweet<\/a><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>\u304a\u6b63\u6708\u4f11\u307f\u3082\u4eca\u65e5\u3067\u7d42\u308f\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002 \u4f55\u51e6\u306b\u3082\u51fa\u304b\u3051\u305a\u5bb6\u3067\u3054\u308d\u3054\u308d\u3057\u3066\u3044\u307e\u3057\u305f\u3002(^_^;) \u5c45\u5834\u6240\u306b\u56f0\u308b\u306e\u3067\u3053\u3046\u3084\u3063\u3066\u30d1\u30bd\u30b3\u30f3\u3067\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u7d44\u3093\u3067\u6642\u9593\u3092\u7121\u99c4\u306b\u4f7f\u3063\u3066\u307e\u3059\u3002 \u4eca\u65e5\u306f PhantomReference \u3092\u8a66\u3057\u3066\u307f\u307e\u3059\u3002 \u305d\u306e\u524d\u306b\u524d\u56de\u3001\u524d\u3005\u56de\u3068 PhantomReference \u306e\u5144\u5f1f\u306e SoftReference \u3068 WeakReference \u306e\u5fa1\u6d5a\u3044\u3092\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002 SoftReference \u306f\u30ea\u30d5\u30a1\u30ec\u30f3\u30c8\u304c\u30bd\u30d5\u30c8\u5230\u9054\u53ef\u80fd\u3068\u306a\u3063\u3066\u3082\u4f7f\u7528\u983b\u5ea6\u3068\u30d2\u30fc\u30d7\u306e\u72b6\u6cc1\u304b\u3089\u3001\u30ac\u30fc\u30d9\u30fc\u30b8\u30fb\u30b3\u30ec\u30af\u30bf\u304c\u30ea\u30d5\u30a1\u30ec\u30f3\u30c8\u3092\u89e3\u653e\u3059\u3079\u304d\u3060\u3068\u5224\u65ad\u3059\u308b\u307e\u3067 GC \u5bfe\u8c61\u306b\u306a\u3089\u306a\u3044\u3002 Weak Refere\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-2714","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\/2714","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=2714"}],"version-history":[{"count":4,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2714\/revisions"}],"predecessor-version":[{"id":2718,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2714\/revisions\/2718"}],"wp:attachment":[{"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2714"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/yucchi.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}