简体   繁体   English

JavaFX TableView WeakListChangeListener内存泄漏?

[英]JavaFX TableView WeakListChangeListener Memory Leak?

I have a JavaFX TableView which is populated using property objects from a bean. 我有一个JavaFX TableView,它使用来自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. 所有列都具有属性,但是在CellFactory update()方法中,一些图形组件用于显示数据,例如带有多个子级的HBox。

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. 一旦通过执行observableList.setAll(copy)以各种方式对表项进行了更新,我还尝试了observableList.clear(),addAll(copy)来查看它是否有所不同。

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. 使用MAT( https://eclipse.org/mat/ ),泄漏嫌疑人表明TableView visibleLeafColumns数据结构似乎保存着大量的WeakListChangeListener对象,这些对象没有被垃圾收集。 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! 该表中有6列,具有250行(每分钟左右左右进行操作),但是运行约30分钟后,注册了80,000个WeakListChangeListeners!

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. 查看TableCell的源代码并假设我正确地阅读了它,似乎只有在创建新TableCell时才将visibleLeafColumns添加到其中,但是我认为TableView已重用了表格单元,因此不应创建该表格单元。 ( http://hg.openjdk.java.net/openjfx/2.2/master/rt/file/e71070b0e0c0/javafx-ui-controls/src/javafx/scene/control/TableCell.java ) 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. 我在几年前在这里找到了类似的帖子( https://community.oracle.com/thread/2354497?tstart=0 ),我想知道是否还有其他人遇到过类似的问题。

Platform: Redhat Linux v6 Java: 1.7.0 update 67 平台:Redhat Linux v6 Java:1.7.0更新67

Any pointers would be really really appreciated. 任何指针将非常感谢。

Thanks, 谢谢,

Andy 安迪

There is a Jira bug report for this issue RT-34970 . 对于此问题RT-34970,有一个Jira错误报告。 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. 这导致TableView整理了visibleLeafColumn对象,并且堆保持明智。

Thanks Jewelsea and Tomas for your suggestions. 感谢Jewelsea和Tomas的建议。 We did try Java 8 which didn't have this memory problem but the performance seemed to degrade over time (12hrs ish). 我们确实尝试了Java 8,但没有出现此内存问题,但是性能似乎随着时间的推移而下降(12小时)。 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). 这似乎与动画有关,因此我们将来在跳转到Java 8时会进行适当的调查(缓存提示无济于事)。

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

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