RFR: 8262518: SwingNode.setContent does not close previous content, resulting in memory leak [v3]
Andy Goryachev
angorya at openjdk.org
Wed Aug 23 15:01:30 UTC 2023
On Wed, 23 Aug 2023 13:21:00 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.
>
> Prasanta Sadhukhan has updated the pull request incrementally with one additional commit since the last revision:
>
> DisposerRecord leak fix
modules/javafx.swing/src/main/java/com/sun/javafx/embed/swing/Disposer.java line 92:
> 90: }
> 91:
> 92: public static void removeRecord(WeakReference ref) {
may be add a javadoc comment?
modules/javafx.swing/src/main/java/javafx/embed/swing/SwingNode.java line 368:
> 366: private void setContentImpl(JComponent content) {
> 367: if (lwFrame != null) {
> 368: rec.dispose();
is it possible for `rec` to be null at this point?
would it make sense to rewrite this code block as
if(rec != null) {
rec.dispose();
rec = null;
}
if(disposeRecRef != null) {
Disposer.removeRecord(...)
disposerRecRef = null;
}
if(lwFrame != null) {
lsFrame = null;
}
?
-------------
PR Review Comment: https://git.openjdk.org/jfx/pull/1219#discussion_r1303153898
PR Review Comment: https://git.openjdk.org/jfx/pull/1219#discussion_r1303151756
More information about the openjfx-dev
mailing list