RFR: 8262518: SwingNode.setContent does not close previous content, resulting in memory leak

John Hendrikx jhendrikx at openjdk.org
Tue Aug 22 11:25:34 UTC 2023


On Tue, 22 Aug 2023 09:54:11 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:

> Issue is when setting the content of a SwingNode, the old content is not garbage collected owing to the fact
> JLightweightFrame is never being released by SwingNodeDisposer
> 
> The SwingNodeDisposer holds an hard pointer to the JLightweightFrame that prevents its collection
> 
> Modified `SwingNode.setContentImpl`  function to use a WeakReference to properly release the memory.

I should note, there is a memory leak still when using `Disposer`.  Each time content is switched, but the `SwingNode` is re-used, a `DisposerRecord` is created that only gets cleaned up when `SwingNode` goes out of scope.  In other words, a million content changes will leave behind a million `DisposerRecord`s.  

So, either there needs to be a `removeRecord` added to `Disposer`, or you could switch to the `TreeShowingProperty` solution.

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

PR Comment: https://git.openjdk.org/jfx/pull/1219#issuecomment-1687998468


More information about the openjfx-dev mailing list