I am using the JavaFX TreeTableView to display sales orders. Parent rows contain the "master" record, and the child rows contain information about the order, including line items for each product ordered. I am using a RowFactory to highlight the rows in the table based on its current status. The code for the RowFactory begins with this code:
currentOrderTree.setRowFactory(new Callback<TreeTableView<MmTicket>, TreeTableRow<MmTicket>>() {
@Override
public TreeTableRow<MmTicket> call(TreeTableView<MmTicket> p) {
final TreeTableRow<MmTicket> row = new TreeTableRow<MmTicket>() {
@Override
protected void updateItem(MmTicket order, boolean empty) {
super.updateItem(order, empty);
if (order != null) {
System.out.println("Calling rowFactory method for the " + ++rowcall + " time.");
if (packingListPendingList.containsKey(order.getSono())) {
if (!getStyleClass().contains("pending")) {
getStyleClass().remove("working");
getStyleClass().remove("fulfilled");
getStyleClass().remove("completed");
getStyleClass().add("pending");
getStyleClass().remove("shipped");
}
....
As you can see, the Callback returns a new TreeTableRow each time the row factory is called. According to the JavaFX 8.0 documentation, it is the system's responsibility to manage the creation of rows, reusing them when appropriate. The System.out.println call documents the number of times the method is called. Scrolling the table up and down a number of times, as well as data refreshes caused by updates to the sales database, result in this method being called tens of thousands of times in a relatively short period of time. My memory usage in the program continues to grow as the TreeTableView is used extensively by the end-users.
Profiling the application shows that there are very large amounts of memory being used by HashTable, and PsuedoClass (css stuff, I believe) and things such as byte[] and char[] and int[]. I have tried different combinations of heap sizes and garbage collectors, but the end result is always the same, in that the application eventually runs out of heap space.
Searching for answers has shown that there are some who are experiencing this problem, and I have found that if I don't do any of the row highlighting, thereby not calling the row factory, the program is much better at managing memory. Anyone have any insights as to what might be causing this problem, or possible solutions?