This discussion is archived
3 Replies Latest reply: Feb 12, 2013 4:47 PM by 915866 RSS

JavaFX Free Memory

862121 Newbie
Currently Being Moderated
Hello everyone,

I hope someone can help me, I'm creating a JavaFX Desktop Application, it's the common desktop application with several windows where you can browse selecting different MenuItems.

The problem comes when I've realized JavaFX never free memory, if I check my windows monitor, the memory is always increasing, even if I do nothing, if I leave the application running, where I know that nothing (developed by me) is running, the memory keeps increasing.
This is not a big problem because, there is a point where it stops.

My main concern is switching between windows, let's say I have two screens, one with the User Management and the other one with Group Management, if I want to load the User Management screen, I empty the main panel, create an instance of User Management and copy all the content into the panel (which I previously deleted all the content).
Now if I have to load the Group Management, I removed all the content of the main panel, create an instance of Group Management and copy all the content of the Group Management into the panel.

The problem with JavaFX is: never free memory, every time I create a new object, the object is there, even if I delete the panel (the object is not referenced, so Garbage Collector should free that memory, but it doesn't).

One extreme thing I did (I'm a bit desperated with this issue) is for every panel, launch a "standalone" window, so when I want to free memory, I just need to close the window, that means the elements of that window won't be referenced by any element, so if I close the window, the memory should be freed. To be clearer let's see this example:
I have a main window, with two options: one for User Management and the other for Group Management.
To open one or other I use

var userMg= UserManagement{};

javafx.stage.Stage {
title: "User Management Window"
scene: userMg.getDesignScene ()
}

or

var groupMg= GroupManagement{};

javafx.stage.Stage {
title: "Group Management Window"
scene: groupMg.getDesignScene ()
}


when executed that a new window is open, a window that I can close and my program keeps executing, the problem is when the window of the User Management or the Group Management is closed the memory is not freed.
Imagine one of that window has 200 checkboxes, images, etc... and it uses like 60-80 MB, I'd like to free that memory, because that window can be opened several times and at certain point, the application becomes extremely slow and needs to be restarted, which is not acceptable.

Any help, please let me know.
Thanks for reading all of this!

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points