Zitat von Nir Lisker <nlis...@gmail.com>:

BTW, Tomas Mikula wrote about this on
http://tomasmikula.github.io/blog/2015/02/10/the-trouble-with-weak-listeners.html
.
There is a comment at the end that is worth a read too.

also interesting is the old (closed as wontfix) bug https://bugs.openjdk.java.net/browse/JDK-8095375 - it's about a very long lived observable (f.i. one holding the current Locale, which hardly ever changes but might) to which all nodes are listening with WeakListeners. Those listeners hang around until the value actually changes - at which time it might be too late to really do any cleanup (either directly throwing a overflow or make the ui unresponsive).

Always thought that the weakListeners are removed from two ends (provided their weakRef is reclaimed):

1. from the listener itself when being notified: it removes itself from the observable if ref is null 2. from the observable itself via its ExpressionHelper which has a trim method that's called on addListener: it seems to throw away all garbage collected weak listeners

1 is ineffective without change notification, and 2 seems to rarely be effective: it's only ever called when the current size of the listeners is exactly its capacity .. which in the example of the bug is after it's too late.

Just musing (didn't test anything) - maybe this is part of the very bad performance of table scrolling (see https://github.com/openjdk/jfx/pull/108) and maybe it is worth improving, after all :)

Reply via email to