package erro; import javafx.application.Application; import javafx.beans.property.ReadOnlyObjectWrapper; import javafx.beans.value.ObservableValue; import javafx.event.Event; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.control.TableCell; import javafx.scene.control.TableColumn; import javafx.scene.control.TableColumn.CellDataFeatures; import javafx.scene.control.TableView; import javafx.scene.layout.VBox; import javafx.stage.Stage; import javafx.util.Callback; import resources.CssUtils; public class TableMemTest extends Application { public static void main(String[] args) { launch(args); } @Override public void start(final Stage stage) throws Exception { final VBox root = new VBox(); root.setPadding(new Insets(10)); final Label memo = new Label("Click to add Tables. GC collect OK. If select row in tables. No GC collect"); root.getChildren().add(memo); final VBox content = new VBox(); content.setPadding(new Insets(10)); root.getChildren().add(content); memo.setOnMouseClicked(new EventHandler() { public void handle(Event arg0) { content.getChildren().clear(); for (int i = 0; i < 100; i++) { content.getChildren().add(createTable()); } memo.setText(updateMen()); }; }); Scene scene = new Scene(root, 850, 500); scene.getStylesheets().add(CssUtils.getCss()); stage.setScene(scene); stage.setTitle("Teste"); stage.show(); } public String updateMen() { Runtime r = Runtime.getRuntime(); r.gc(); long total = r.totalMemory(); long max = r.maxMemory(); long used = total - r.freeMemory(); return "" + ((double)used / 1024 / 1024) + "/" + ((double)total / 1024 / 1024); } public TableView createTable() { TableView tableView1 = new TableView<>(); tableView1.setMinHeight(100); tableView1.setPrefHeight(100); tableView1.setPrefWidth(800); tableView1.getColumns().addAll(createColumn("Column1", 100), createColumn("Column2", 400), createColumn("Column3", 50)); tableView1.getItems().add(new String[] {"Valor 1", "Valor 2", "Valor 3"}); tableView1.getItems().add(new String[] {"Valor 1", "Valor 2", "Valor 3"}); tableView1.getItems().add(new String[] {"Valor 1", "Valor 2", "Valor 3"}); tableView1.getItems().add(new String[] {"Valor 1", "Valor 2", "Valor 3"}); tableView1.getItems().add(new String[] {"Valor 1", "Valor 2", "Valor 3"}); tableView1.getItems().add(new String[] {"Valor 1", "Valor 2", "Valor 3"}); tableView1.getItems().add(new String[] {"Valor 1", "Valor 2", "Valor 3"}); tableView1.getItems().add(new String[] {"Valor 1", "Valor 2", "Valor 3"}); return tableView1; } public TableColumn createColumn(String text, int w) { TableColumn tableColumn = new TableColumn<>(); tableColumn.setText(text); tableColumn.setPrefWidth(w); tableColumn.setCellValueFactory(new Callback, ObservableValue>() { @Override public ObservableValue call(CellDataFeatures cell) { try { return new ReadOnlyObjectWrapper("Valor X"); } catch (Exception e) { e.printStackTrace(); return null; } } }); tableColumn.setCellFactory(new Callback, TableCell>() { @Override public TableCell call(TableColumn column) { return new TableCell<>(); } }); return tableColumn; } }