• <bdo id='B4bh0'></bdo><ul id='B4bh0'></ul>

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

    <tfoot id='B4bh0'></tfoot>
        <legend id='B4bh0'><style id='B4bh0'><dir id='B4bh0'><q id='B4bh0'></q></dir></style></legend>

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

      1. Java有析构函数吗?

        Is there a destructor for Java?(Java有析构函数吗?)
            <i id='awcI3'><tr id='awcI3'><dt id='awcI3'><q id='awcI3'><span id='awcI3'><b id='awcI3'><form id='awcI3'><ins id='awcI3'></ins><ul id='awcI3'></ul><sub id='awcI3'></sub></form><legend id='awcI3'></legend><bdo id='awcI3'><pre id='awcI3'><center id='awcI3'></center></pre></bdo></b><th id='awcI3'></th></span></q></dt></tr></i><div id='awcI3'><tfoot id='awcI3'></tfoot><dl id='awcI3'><fieldset id='awcI3'></fieldset></dl></div>
              <bdo id='awcI3'></bdo><ul id='awcI3'></ul>
              <legend id='awcI3'><style id='awcI3'><dir id='awcI3'><q id='awcI3'></q></dir></style></legend>

                <tbody id='awcI3'></tbody>
            • <tfoot id='awcI3'></tfoot>

                • <small id='awcI3'></small><noframes id='awcI3'>

                  本文介绍了Java有析构函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Java 有析构函数吗?我似乎无法找到任何有关此的文档.如果没有,我怎样才能达到同样的效果?

                  Is there a destructor for Java? I don't seem to be able to find any documentation on this. If there isn't, how can I achieve the same effect?

                  为了使我的问题更具体,我正在编写一个处理数据的应用程序,并且规范说应该有一个重置"按钮,可以将应用程序恢复到其刚启动的原始状态.但是,除非应用程序关闭或按下重置按钮,否则所有数据都必须是实时的".

                  To make my question more specific, I am writing an application that deals with data and the specification say that there should be a 'reset' button that brings the application back to its original just launched state. However, all data have to be 'live' unless the application is closed or reset button is pressed.

                  我通常是一名 C/C++ 程序员,我认为这很容易实现.(因此我计划最后实现它.)我构建了我的程序,使所有可重置"对象都在同一个类中,这样我就可以在按下重置按钮时销毁所有活动"对象.

                  Being usually a C/C++ programmer, I thought this would be trivial to implement. (And hence I planned to implement it last.) I structured my program such that all the 'reset-able' objects would be in the same class so that I can just destroy all 'live' objects when a reset button is pressed.

                  我在想如果我所做的只是取消引用数据并等待垃圾收集器收集它们,如果我的用户重复输入数据并按下重置按钮,会不会出现内存泄漏?我也在想,既然 Java 作为一门语言已经相当成熟,应该有一种方法可以防止这种情况发生或优雅地解决这个问题.

                  I was thinking if all I did was just to dereference the data and wait for the garbage collector to collect them, wouldn't there be a memory leak if my user repeatedly entered data and pressed the reset button? I was also thinking since Java is quite mature as a language, there should be a way to prevent this from happening or gracefully tackle this.

                  推荐答案

                  因为 Java 是一种垃圾收集语言,所以您无法预测对象何时(或什至)会被销毁.因此没有直接等效的析构函数.

                  Because Java is a garbage collected language you cannot predict when (or even if) an object will be destroyed. Hence there is no direct equivalent of a destructor.

                  有一个名为finalize 的继承方法,但这完全由垃圾收集器决定调用.所以对于需要明确整理的类,约定是定义一个 close 方法并使用 finalize 仅用于完整性检查(即如果 close 没有被调用,现在就做并记录错误).

                  There is an inherited method called finalize, but this is called entirely at the discretion of the garbage collector. So for classes that need to explicitly tidy up, the convention is to define a close method and use finalize only for sanity checking (i.e. if close has not been called do it now and log an error).

                  最近有一个引发对finalize的深入讨论的问题,所以如果需要的话应该提供更多的深度......

                  There was a question that spawned in-depth discussion of finalize recently, so that should provide more depth if required...

                  这篇关于Java有析构函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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='h3aiD'><style id='h3aiD'><dir id='h3aiD'><q id='h3aiD'></q></dir></style></legend>
                • <i id='h3aiD'><tr id='h3aiD'><dt id='h3aiD'><q id='h3aiD'><span id='h3aiD'><b id='h3aiD'><form id='h3aiD'><ins id='h3aiD'></ins><ul id='h3aiD'></ul><sub id='h3aiD'></sub></form><legend id='h3aiD'></legend><bdo id='h3aiD'><pre id='h3aiD'><center id='h3aiD'></center></pre></bdo></b><th id='h3aiD'></th></span></q></dt></tr></i><div id='h3aiD'><tfoot id='h3aiD'></tfoot><dl id='h3aiD'><fieldset id='h3aiD'></fieldset></dl></div>

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

                        • <tfoot id='h3aiD'></tfoot>
                            <bdo id='h3aiD'></bdo><ul id='h3aiD'></ul>
                              <tbody id='h3aiD'></tbody>