RFR: 8088420: JavaFX WebView memory leak via EventListener
Kevin Rushforth
kcr at openjdk.java.net
Thu May 19 15:27:01 UTC 2022
On Thu, 19 May 2022 13:13:01 GMT, Jay Bhaskar <jbhaskar at openjdk.org> wrote:
> This PR is new implementation of JavaEvent listener memory management.
> Issue [JDK-8088420](https://bugs.openjdk.java.net/browse/JDK-8088420?filter=-1)
>
> 1. Calling remove event listener does not free jni global references.
> 2. When WebView goes out of scope (disposed from app) , its Event Listeners are not being garbage collected.
>
> Solution:
> 1. Detached the jni global reference from JavaEventListener.
> 2. Create scoped ref counted wrapper class JavaObjectWrapperHandler for jni global reference.
> 3. Create unique JavaObjectWrapperHandler object for each JavaEventListener.
> 4. EventListenerManager is a singleton class , which stores the JavaObjectWrapperHandler mapped with JavaEventListener.
> 5. EventListenerManager also stores the JavaEventListener mapped with DOMWindow.
> 6. When Event listener explicitly removed , JavaEventListener is being forwarded to EventListenerManager to clear the listener.
> 7. When WebView goes out of scope, EventListenerManager will de-registered all the event listeners based on the ref counts attached with WebView DOMWindow.
While testing, I noticed one problem in that the new unit tests calls `Platform.exit()` (this was my fault for adding it when sending you the test case), causing any subsequent web test to fail.
modules/javafx.web/src/test/java/test/javafx/scene/web/EventListenerLeakTest.java line 113:
> 111: public static void cleanupOnce() {
> 112: Platform.exit();
> 113: }
I just noticed that this will cause subsequent tests to fail. Unit tests should not call `Platform.exit()` (as opposed to system tests, which should). You can remove the entire method.
-------------
PR: https://git.openjdk.java.net/jfx/pull/799
More information about the openjfx-dev
mailing list