简体   繁体   中英

Java FX 2 Heap Space

There are several fxml files and controllers in my Java FX 2 application.

  1. LayoutController is layout.fxml controller that contains static layout element BorderPane. This controller has some methods:
  • BorderPane.setHeader (Some method through which load header.fxml file and return Node)
  • BorderPane.setCenter (Some method through which load center.fxml file and return Node)
  • initialize(URL url, ResourceBundle resourceBundle) in which setHeader method calls.

  1. HeaderController is header.fxml controller that contains control element TabPane. HeaderController has onSelected EventHandler. On this action into BorderPane.center inserts center.fxml.

  2. CenterController is center.fxml controller that on initialize inserts control element TableView and fills it with data.

My problem is in memory leak. I get heap space while repeatedly selected tabs.

Did you try making use of JVM option -XX:+HeapDumpOnOutOfMemoryError ? You can read more about on this here

You should try to focus if the UI objects are getting recreated on each click rather than getting reused ? Please read following links to have more idea on this : 1) Memory Leaks in JavaFX 2) Node object not getting GCed

Realized method, that cleans all data in previous created controller like this:

public void dispose() {

 table.getColumns().clear();

 table.getItems.clear();

 table = null;
}

Is this the correct approach?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM