Integrated: 8373908: XYChart (ScatteredChart) leaks memory when removing data

John Hendrikx jhendrikx at openjdk.org
Mon Dec 22 18:54:58 UTC 2025


On Thu, 18 Dec 2025 02:07:22 GMT, John Hendrikx <jhendrikx at openjdk.org> wrote:

> Fixes a problem with leaked references in XYChart.  A few things conspire here to make this into a memory leak:
> 
> - The weak bindings used by StringBinding leave behind listener "stubs" when GC'd; that's just how they work, it is a "strong" listener that wraps a weak referenced listener.  The strong part remains behind, and is cleaned up when a new listener is added/removed by ExpressionHelper (and if that never happens, those stubs remain there indefinitely).
> - The fluent bindings (map/flatMap/orElse) use normal listeners, but only when they are observed themselves (lazy listeners)
> - The "stub" that is left behind counts as being observed, so the fluent bindings don't unsubscribe themselves
> 
> The leak has nothing to do with the node or the accessible property, but purely by the StringBinding leaving behind stubs on the flat mapped properties.
> 
> The leak is actually because the Series to which the Data object belongs is referencing the Data object.  The flatMaps track the series object so they added a listener to the series object, and they think they are observed indefinitely because of the listener stub.
> 
> The easiest solution here is to ensure the Series object is not tracked when not needed; this can be achieved by setting the series to `null` in the ListChangeListener for the Data list.

This pull request has now been integrated.

Changeset: b39e1faa
Author:    John Hendrikx <jhendrikx at openjdk.org>
URL:       https://git.openjdk.org/jfx/commit/b39e1faab49f1ec7529f7dfe91f7f58950bf4db7
Stats:     34 lines in 1 file changed: 19 ins; 13 del; 2 mod

8373908: XYChart (ScatteredChart) leaks memory when removing data

Reviewed-by: kcr, angorya

-------------

PR: https://git.openjdk.org/jfx/pull/2013


More information about the openjfx-dev mailing list