Efficiently closing a JFrame in Java

0

Good friends, I have a question for you. Does anyone know how to close a JFrame and in doing so release the memory that was used in that window? Pass the following, I have an application in which I log in and open a JFrame that acts as the main menu. One of the items in this menu is another JFrame, in which a report of all the economic activities of the clients is presented. I have it in a JTable and not in an IReport because once requested that data, they are loaded in a JTable and said data are manipulated (ordering, search of the major, search of the minor, grouping according to the desired at a certain time, etc.) . For each record of that JTable I can access the transaction detail, for which another JFrame opens with that data. This is the problem Every time I open the auxiliary windows the use of memory grows, and when I close it, it no longer goes down, it stays in that maximum, limiting the use of memory.

I would be grateful if anyone knows another way to close the window and release resources, because if I close in this way JFrame.EXIT_ON_CLOSE , I close the entire application. I'm currently closing it with JFrame.DISPOSE_ON_CLOSE

    
asked by Carlos 27.03.2017 в 23:23
source

1 answer

2

If you avoid having references to the JFrame the GC (garbage collect) worries about that for you. If you want to make it easier for GC to do it for you, avoid bidirectional references or use WeakReference where appropriate.

The virtual machine runs the gc each time, it is noticeable when you take a profile of your memory usage. If you want to check if the GC can clean your JFrame after closing, you can call System.gc() after the close and see if anything changes in memory usage.

If you need more information about what is happening in your virtual machine, you can use for example jvisualvm . In this link about refinement of gc you find more help on the subject (which is a bit broad).

    
answered by 27.03.2017 / 23:43
source