简体   繁体   中英

JavaFX TableView WeakListChangeListener Memory Leak?

I have a JavaFX TableView which is populated using property objects from a bean. All the columns have properties but in the CellFactory update() method some graphical components are used for displaying data such as an HBox with several children.

There is also a row factory which sets a style on the whole row when a status of that row changes.

The data in the table is updated and resorted in an array list which is a copy of the items in the table created from the observable list. Once the copy list is manipulated in various ways the table items are updated by doing an observableList.setAll(copy), I've also tried a observableList.clear(), addAll(copy) to see if it makes any difference.

The problem is that over time there appears to be a memory leak. Using MAT ( https://eclipse.org/mat/ ) the leak suspects show the TableView visibleLeafColumns data structure seems to hold an enormous quantity WeakListChangeListener objects which are not being garbage collected. There are 6 columns in the table which has 250 rows (being manipulated every minute or so) but after running for about 30mins there are 80,000 WeakListChangeListeners registered!

Looking at the source code for the TableCell and assuming I'm reading it correctly it appears that the visibleLeafColumns is only added to when a new TableCell is created but I thought that the table cells were reused by the TableView and therefore shouldn't be created. ( http://hg.openjdk.java.net/openjfx/2.2/master/rt/file/e71070b0e0c0/javafx-ui-controls/src/javafx/scene/control/TableCell.java )

I found a similar post from a couple of years ago here ( https://community.oracle.com/thread/2354497?tstart=0 ) and I wondered if anyone else has come across a similar problem.

Platform: Redhat Linux v6 Java: 1.7.0 update 67

Any pointers would be really really appreciated.

Thanks,

Andy

There is a Jira bug report for this issue RT-34970 . My colleague solved this issue by periodically removing all the columns and adding them back. That caused the TableView to tidy up the visibleLeafColumn object and the heap stayed sensible.

Thanks Jewelsea and Tomas for your suggestions. We did try Java 8 which didn't have this memory problem but the performance seemed to degrade over time (12hrs ish). This appeared to be related to animations so we'll investigate that properly when we make the jump to Java 8 in the future (cache hint didn't help).

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