JDK-8116148 : Memory Leak: event handlers of root TreeItem are not removed
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: fx2.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Cannot Reproduce
  • Submitted: 2011-08-30
  • Updated: 2022-10-21
  • Resolved: 2013-12-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8Resolved
Related Reports
Relates :  
Relates :  
Description
TreeViewMemTest (attached) run in static mode and 16mb of heap fails with OOM after ~65,000 iterations.
The reason is because event handlers reachable from root TreeItem are not removed.
As results there are more than 262,000 WeakEventHandlers which occupy more than 12Mb.
See full root path in attached TreeView_heap.jpg.

The test just creates new TreeView object with 31 static TreeItems (created at the beginning of the test)
on each pulse. TreeView object created on previous pulse is removed before new one is created.
So, only one TreeView object exists at any moment of time.

Steps to run the test:
> java -Xmx16m -verbose:gc -XX:+HeapDumpOnOutOfMemoryError -cp "..." TreeViewMemTest -mode static

There is no such memory issue in case the test is run in dynamic mode (-mode dynamic). 

Comments
Requesting deferral as this is a minor leak and is unlikely to be able to be resolved prior to ZBB.
09-10-2013

Reopen the issue as not fixed.
04-09-2012

Changeset: 6ca66c53de08 Author: jgiles Date: Fri Aug 24 09:42:03 2012 +1200 URL: http://jfxsrc.us.oracle.com/javafx/8.0/scrum/controls/rt/rev/6ca66c53de08
23-08-2012

This can probably be fixed with the same approach used in RT-24098, except for WeakEventHandler rather than WeakListChangeListener. I will look into this next week.
10-08-2012

Partial fixes pushed to controls 2.0.2 repo. Further fix is in attached patch, which has not yet been fully discussed / analysed. However, after applying the patch the memory leak is gone. There needs to be further discussion around whether this is a viable approach to the issue. This patch fixes a problem in WeakEventHandler where the WeakReference is cleared, but the WeakReference itself, and the WeakEventHandler, remain in memory indefinitely as the TreeItem retains a reference to the WeakEventHandler, and no events are fired so the handle method is never called to clean up 'empty' WeakReferences. A similar issue exists in the other weak* classes (WeakListChangeListener and WeakInvalidationListener).
12-10-2011

Can you please give more detailed instructions on how to run this test?
11-10-2011