How should i clean up a TableView
instance from memory,
From what i learnt,
listeners
attached to the table. (is it applicable even to the respective table's columns and rows?) From an external reference i did the following,
setSelectionModel
to null. setItems
to an empty ObservableArraylist
. Finally, My code looks something like below.
//I gave a try for, RowFactory and ColumnFactory to null.
tableView.setRowFactory(null);
for (TableColumn column : this.tableView.getColumns()) {
column.setCellFactory(null);
column.setCellValueFactory(null);
}
tableView.getFocusModel().focus(null);
tableView.setOnMouseClicked(null);
tableView.setSelectionModel(null);
tableView.getColumns().clear();
tableView.setItems(FXCollections.observableArrayList());
tableView = null;
My problem is:
I have multiple table views opened and when i close, ( HashMapNode
(got from profiler) related to TableView
is still on memory and not released) So whenever i close a tableView i call the above code.
Also, I use inner classes to setCellFactory
like below,
column.setCellFactory((TableColumn<?, ?> param) -> new EditingTableCell());
private class EditingTableCell extends TableCell<?, ?> {
//.....
}
So, How should i properly clean up a TableView
instance so that it will be garbage collected.
Java Version : 1.8.0_45
JavFX Version : 8.0.45-b11
3 ( No strong reference to the table instance ) should be enough.
Listeners are weak references that do not prevent the GC from cleaning up the object, if there are no more strong references to it.
However, if the TableView is contained within a Tab, it might not be GC'd upon tab closing, because JavaFX in its internals keeps a strong reference to the last closed tab (a gotcha it took me a while to find out - I consider it an undesired bug-like behaviour).
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.