How do I delete an object referenced by a dialog?

后端 未结 8 2599
独厮守ぢ
独厮守ぢ 2021-02-14 11:42

I created a dialog with a jpanel inside it, and that jpanel will be still referenced if I get rid of the dialog. I want to destroy that dialog and everything in it when I click

8条回答
  •  天命终不由人
    2021-02-14 12:36

    1. If it is a Window and if it is visible

      I. frame.setVisible(false);

      II. frame.dispose();

      II. set reference to null (ex.. frame=null;)

    2. If it is not a Window

      I.set reference to null (ex.. x=null;)

    That is all , once object be free GC will free the resources when it is like.

    Here are somethings you must understand

    *. You as Java programmer can not force Garbage collection in Java; it will only trigger if JVM thinks it needs a garbage collection based on Java heap size.

    *. There are methods like System.gc () and Runtime.gc () which is used to send request of Garbage collection to JVM but it’s not guaranteed that garbage collection will happen.

    *. If there is no memory space for creating new object in Heap Java Virtual Machine throws OutOfMemoryError or java.lang.OutOfMemoryError heap space

    And search about this...

    J2SE 5(Java 2 Standard Edition) adds a new feature called Ergonomics . goal of ergonomics is to provide good performance from the JVM with minimum of command line tuning.

提交回复
热议问题