RFR: 8314755: Resource leak: SwingWorker listener keeps strong reference to executor [v4]

Christopher Sahnwaldt duke at openjdk.org
Tue Sep 12 15:03:57 UTC 2023


On Tue, 12 Sep 2023 12:34:12 GMT, Christopher Sahnwaldt <duke at openjdk.org> wrote:

>> In https://github.com/openjdk/jdk/commit/b8af3d50192f8bc98d83f8102f0fd1989f302e32 the weak reference was accidentally changed from a field to a local variable, which means that the PropertyChangeListener keeps a strong reference to executorService, which is a resource leak
>
> Christopher Sahnwaldt has updated the pull request incrementally with one additional commit since the last revision:
> 
>   SwingWorkerExecutorLeakTest.java: use AppContext.getAppContext() instead of SunToolkit.createNewAppContext() to create AppContext, set necessary system properties

I just found [this comment](https://bugs.openjdk.org/browse/JDK-8289616?focusedCommentId=14516108#comment-14516108) by @prrace: "AppContext.dispose() is no longer called from anywhere in JDK code." So as I explained in my previous comment, this is a non-issue. I'll close it.

Arguably, there still is a resource leak, because the executor created in `SwingWorker.getWorkersExecutorService()` is never shut down. But that's probably only relevant if there is a significant time span in which the JVM is still running but the `AppContext` isn't needed anymore. I guess such a situation only occurs if an application starts a GUI, later shuts down the GUI, but keeps the JVM running. Should be pretty rare.

Anyway, my suggested fix won't help, because it depends on `AppContext.dispose()` being called, which will never happen. Sorry for the waste of time. :-)

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

PR Comment: https://git.openjdk.org/jdk/pull/15081#issuecomment-1715896997


More information about the client-libs-dev mailing list