Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8117780

Memory leak in TableView - WeakListChangeListeners accumulate forever


    • Type: Bug
    • Status: Resolved
    • Priority: P2
    • Resolution: Cannot Reproduce
    • Affects Version/s: 7u45
    • Fix Version/s: 8
    • Component/s: javafx
    • Environment:

      Oracle JDK 1.7.45, Ubuntu 13.04


      It looks like every table row (or maybe even every cell) registers a WeakListChangeListener to the list of visible columns (tableView.getVisibleLeafColumns()).

      When we keep adding and removing rows to/from the table, the list of weak listeners keeps growing. Even though the actual cells get garbage collected properly, the empty obsolete weak listeners remain hanging there forever. The list of listeners gets cleaned up only if a relevant event occurs (i.e. a column is hidden, shown, added, removed). Otherwise the list keeps growing forever.

      This causes two problems:
      * memory leak - each weak listener consumes only a few dozen bytes, but in a real-life application where the table gets updated frequently, there are soon millions of these, which then occupy hundreds of megabytes.
      * Stuck application - when an event actually occurs (e.g. a column gets hidden), the table iterates through the millions of obsolete listeners (in the FX thread) and the application gets stuck sometimes for minutes.

      See the attached example. A very simple table, it keeps adding and removing rows. Leave it running for a few minutes, then look at it in a profiler. There will be tens or hundreds of thousands WeakListChangeListeners (with the actual listeners garbage-collected) attached to visibleLeafColumns.




            • Assignee:
              jgiles Jonathan Giles
              jmarekjfx Jan Marek (Inactive)
            • Votes:
              0 Vote for this issue
              2 Start watching this issue


              • Created: