Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java swing gui memory allocation

Hi I was wondering if there is a way to set a jbutton to do the equivalent of setdefaultcloseoperation(JFrame.DISPOSE_ON_CLOSE) because I dont understand how a frame object is eligible for collection if it still has listeners when the frame is set invisible. I can send code if this doesn't make sense.

like image 652
Ben Evans Avatar asked Dec 05 '25 02:12

Ben Evans


1 Answers

  • Top Level Containers (JFrame, JDialog ...) miss implemetations for finalize(), then they are never GC'd

  • equivalent for JFrame.DISPOSE_ON_CLOSE is only setVisible(false)

  • you can returns all Top Level Containers from method Window[] wins = Window.getWindows();

  • you can remove only all JComponents from ContentPane, for return used memory back

EDIT

  • only visible container with Focus can listening or firing events from Swing Listeners
like image 58
mKorbel Avatar answered Dec 06 '25 15:12

mKorbel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!