简体   繁体   English

Java FX 2 堆空间

[英]Java FX 2 Heap Space

There are several fxml files and controllers in my Java FX 2 application.我的 Java FX 2 应用程序中有几个 fxml 文件和控制器。

  1. LayoutController is layout.fxml controller that contains static layout element BorderPane. LayoutController 是 layout.fxml 控制器,包含静态布局元素 BorderPane。 This controller has some methods:这个控制器有一些方法:
  • BorderPane.setHeader (Some method through which load header.fxml file and return Node) BorderPane.setHeader (加载 header.fxml 文件并返回 Node 的一些方法)
  • BorderPane.setCenter (Some method through which load center.fxml file and return Node) BorderPane.setCenter (加载center.fxml文件并返回Node的一些方法)
  • initialize(URL url, ResourceBundle resourceBundle) in which setHeader method calls. initialize(URL url, ResourceBundle resourceBundle)其中 setHeader 方法调用。

  1. HeaderController is header.fxml controller that contains control element TabPane. HeaderController 是包含控制元素 TabPane 的 header.fxml 控制器。 HeaderController has onSelected EventHandler. HeaderController 有 onSelected EventHandler。 On this action into BorderPane.center inserts center.fxml.在此操作中插入 BorderPane.center 插入 center.fxml。

  2. CenterController is center.fxml controller that on initialize inserts control element TableView and fills it with data. CenterController 是 center.fxml 控制器,它在初始化时插入控制元素 TableView 并用数据填充它。

My problem is in memory leak.我的问题是内存泄漏。 I get heap space while repeatedly selected tabs.我在重复选择选项卡时获得堆空间。

Did you try making use of JVM option -XX:+HeapDumpOnOutOfMemoryError ?您是否尝试使用 JVM 选项 -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 ?如果 UI 对象在每次点击时重新创建而不是被重用,您应该尝试集中注意力吗? Please read following links to have more idea on this : 1) Memory Leaks in JavaFX 2) Node object not getting GCed请阅读以下链接以对此有更多了解:1) JavaFX 中的内存泄漏2) 节点对象没有被 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?这是正确的方法吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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