import javax.swing.*; public class Main { public Main() { JFrame jf = new JFrame(\"Demo\"); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
The frame is visible and the reference to the object is reachable by at least one of the GUI threads (the Event Dispatch Thread). That is why it isn't garbage collected.
If you want it to disapear, use frame.dispose().