JFrame 对象准备好进行垃圾回收的条件

Conditions for a JFrame object to be ready for garbage collection

this thread,我了解到,即使程序员没有剩余的对象引用(变得不可访问),它也可能还没有准备好进行垃圾回收。一个不可达但是 运行 Thread 还没有加入就是这样的例子。我的问题是:尚未关闭的无法访问的 JFrame 是否已准备好进行垃圾回收?如果答案是肯定的,这种行为会破坏或强制关闭 GUI 界面吗?例如,以下代码片段摘自 Java 一书:A Beginner's Guide:

class SwingDemo {
  SwingDemo() {
    JFrame jfrm = new JFrame("A Simple Swing Application");
    jfrm.setSize(275, 100);
    jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JLabel jlab = new JLabel(" Swing defines the modern Java GUI.");
    jfrm.add(jlab);
    jfrm.setVisible(true);
  }
  ...
}

请注意,当 SwingDemo 构造函数 returns 时,创建的 JFrame 对象不再可访问。

您的一个假设是错误的:JFrame 可访问的,一种方法是通过 Windows#getWindows()。此方法上的 JVM:

Returns an array of all Windows, both owned and ownerless, created by this application. If called from an applet, the array includes only the Windows accessible by that applet.