<bdo id='vdKuy'></bdo><ul id='vdKuy'></ul>

      <small id='vdKuy'></small><noframes id='vdKuy'>

    1. <tfoot id='vdKuy'></tfoot>
      <legend id='vdKuy'><style id='vdKuy'><dir id='vdKuy'><q id='vdKuy'></q></dir></style></legend>

      1. <i id='vdKuy'><tr id='vdKuy'><dt id='vdKuy'><q id='vdKuy'><span id='vdKuy'><b id='vdKuy'><form id='vdKuy'><ins id='vdKuy'></ins><ul id='vdKuy'></ul><sub id='vdKuy'></sub></form><legend id='vdKuy'></legend><bdo id='vdKuy'><pre id='vdKuy'><center id='vdKuy'></center></pre></bdo></b><th id='vdKuy'></th></span></q></dt></tr></i><div id='vdKuy'><tfoot id='vdKuy'></tfoot><dl id='vdKuy'><fieldset id='vdKuy'></fieldset></dl></div>

      2. 为什么存在WeakHashMap,却没有WeakSet?

        Why does exist WeakHashMap, but absent WeakSet?(为什么存在WeakHashMap,却没有WeakSet?)

        <legend id='lpYW0'><style id='lpYW0'><dir id='lpYW0'><q id='lpYW0'></q></dir></style></legend>

        <small id='lpYW0'></small><noframes id='lpYW0'>

      3. <tfoot id='lpYW0'></tfoot>

              <i id='lpYW0'><tr id='lpYW0'><dt id='lpYW0'><q id='lpYW0'><span id='lpYW0'><b id='lpYW0'><form id='lpYW0'><ins id='lpYW0'></ins><ul id='lpYW0'></ul><sub id='lpYW0'></sub></form><legend id='lpYW0'></legend><bdo id='lpYW0'><pre id='lpYW0'><center id='lpYW0'></center></pre></bdo></b><th id='lpYW0'></th></span></q></dt></tr></i><div id='lpYW0'><tfoot id='lpYW0'></tfoot><dl id='lpYW0'><fieldset id='lpYW0'></fieldset></dl></div>
                <bdo id='lpYW0'></bdo><ul id='lpYW0'></ul>

                  <tbody id='lpYW0'></tbody>
                  本文介绍了为什么存在WeakHashMap,却没有WeakSet?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  来自 J.布洛赫

                  ... 内存泄漏的来源是听众... 最好的方法来确保回调被垃圾收集及时是只存储弱对它们的引用,例如,通过仅将它们作为键存储在WeakHashMap.

                  A ... source of memory leaks is listeners ... The best way to ensure that callbacks are garbage collected promptly is to store only weak references to them, for instance, by storing them only as keys in a WeakHashMap.

                  那么,为什么 Java Collections 框架中没有 WeakSet?

                  So, why there isn't any WeakSet in the Java Collections framework?

                  推荐答案

                  Collections.newSetFromMap

                  Set<Object> weakHashSet = 
                      Collections.newSetFromMap(
                          new WeakHashMap<Object, Boolean>()
                      );
                  

                  Collections.newSetFromMap 文档,传递一个 WeakHashMap 获取 Set.

                  这篇关于为什么存在WeakHashMap,却没有WeakSet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Maven JAVA_HOME environment variable is not defined correctly, but it is(Maven JAVA_HOME 环境变量未正确定义,但它是)
                  Java System Environment Variable(Java 系统环境变量)
                  Java -classpath option(Java -classpath 选项)
                  Read environment variable in SpringBoot(在 SpringBoot 中读取环境变量)
                  Tomcat 8 - context.xml use Environment Variable in Datasource(Tomcat 8 - context.xml 在数据源中使用环境变量)
                  Issue with JAVA_HOME(JAVA_HOME 的问题)

                    <legend id='qIpxn'><style id='qIpxn'><dir id='qIpxn'><q id='qIpxn'></q></dir></style></legend>

                          <bdo id='qIpxn'></bdo><ul id='qIpxn'></ul>

                            <i id='qIpxn'><tr id='qIpxn'><dt id='qIpxn'><q id='qIpxn'><span id='qIpxn'><b id='qIpxn'><form id='qIpxn'><ins id='qIpxn'></ins><ul id='qIpxn'></ul><sub id='qIpxn'></sub></form><legend id='qIpxn'></legend><bdo id='qIpxn'><pre id='qIpxn'><center id='qIpxn'></center></pre></bdo></b><th id='qIpxn'></th></span></q></dt></tr></i><div id='qIpxn'><tfoot id='qIpxn'></tfoot><dl id='qIpxn'><fieldset id='qIpxn'></fieldset></dl></div>

                            <tfoot id='qIpxn'></tfoot>
                          1. <small id='qIpxn'></small><noframes id='qIpxn'>

                              <tbody id='qIpxn'></tbody>