Java swing gui memory allocation

Hi, I was wondering if there is a way to set jbutton to execute the equivalent of setdefaultcloseoperation (JFrame.DISPOSE_ON_CLOSE), because I don’t understand how the frame object has the right to collect, if it still has listeners, when the frame is set invisible, I can send the code if it does not make sense.

+3
source share
2 answers
  • Top-level containers ( JFrame, JDialog...) skip spaces for finalize(), then they will never be gC'd

  • equivalent to JFrame.DISPOSE_ON_CLOSE- it's onlysetVisible(false)

  • you can return all top level containers from a method Window[] wins = Window.getWindows();

  • JComponents ContentPane,

+2
addActionListener( new ActionListener(){
            public void actionPerformed(ActionEvent e){
                   myframe.dispose();
                   }
            });
+1

All Articles