用于GUI元素的垃圾收集器 [英] Garbage Collector for GUI elements

查看:98
本文介绍了用于GUI元素的垃圾收集器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在理解以下代码时遇到问题:

I have a problem with understanding the following code:

import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.*;

public class A
{
      public A(){
        JFrame myframe = new JFrame ("hz window");
        myframe.setLayout(new GridLayout ());
        myframe.setSize(new Dimension (500, 200));
        myframe.setVisible(true);
    }

    public static void main (String arg[]){
        new A();
        //  System.gc();                          //1
          //Runtime.getRuntime().gc();            //2
    }
}

myframe对象的范围是构造函数A类,对吧?

The scope of myframe object is the constructor of class A,right?

然后,为什么窗口没有消失(即第1行和第2行的垃圾收集器删除)

Then, why is the window not dissapeared (i.e.,removed by garbage collector in lines 1 and 2)

我们在java程序中创建的所有gui元素的范围是什么?

What is the scope of all gui elements we create in java program?

JVM在哪里保存应用程序gui对象的所有链接?

Where does JVM keep all the links to the application's gui objects?

对不起新手问题我很抱歉。

I'm sorry for newbie questions.

推荐答案

Swing保持一个引用每个窗口对象,直到它们被用户关闭或使用 dispose()函数强行处理。否则,你会看到神秘的消失GUI元素。

Swing keeps a reference to every window object until they are closed by user or disposed forcefully using dispose() function. Otherwise, you would see mysteriously dissapearing GUI elements.

这篇关于用于GUI元素的垃圾收集器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆