Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8292180 | jfx17.0.5 | Ambarish Rapte | P3 | Resolved | Fixed | |
JDK-8287795 | 8u351 | Dukebot | P3 | Resolved | Fixed | b01 |
JDK-8289474 | 8u341 | Ambarish Rapte | P3 | Resolved | Fixed | b31 |
JDK-8287852 | 8u333 | Ambarish Rapte | P3 | Closed | Fixed | b32 |
JDK-8292551 | jfx11.0.17 | Ambarish Rapte | P3 | Resolved | Fixed |
I found out that calling eventtarget.removeEventListener doesn't remove the Eventlistener so it's being garbage collected.
If you run this code:
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker.State;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import org.w3c.dom.events.Event;
import org.w3c.dom.events.EventListener;
import org.w3c.dom.events.EventTarget;
public class WebViewTest extends Application{
private Scene scene;
private Pane top;
private Pane bottom;
private EventListener listener;
public static void main(String[] args) throws Exception {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setScene(new Scene(new BorderPane()));
scene = primaryStage.getScene();
top = new HBox();
((BorderPane)scene.getRoot()).setTop(top);
bottom = new HBox();
((BorderPane)scene.getRoot()).setBottom(bottom);
addWebView();
Button but = new Button();
but.setText("add and remove eventlistener");
but.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
addWebView();
}
});
bottom.getChildren().add(but);
primaryStage.show();
}
public void addWebView() {
top.getChildren().clear();
final WebView webView = new WebView();
top.getChildren().add(webView);
webView.getEngine().loadContent("HELLO");
listener = new EventListener() {
@Override
public void handleEvent(Event evt) {
}
};
webView.getEngine().getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
@Override
public void changed(ObservableValue<? extends State> arg0, State arg1, State arg2) {
if (arg2 == State.SUCCEEDED) {
EventTarget target = (EventTarget) webView.getEngine().getDocument().getDocumentElement();
target.addEventListener("keydown",listener , false);
webView.getEngine().getLoadWorker().stateProperty().removeListener(this);
target.removeEventListener("keydown",listener , false);
listener = null;
}
}
});
}
}
And clicking on the button for example 10 times, then when you look in for example JProfiler, so can see 10 instances of EventListenerImpl, and it never decreases.. Isn't this a bug?
Best regards
Troels
- backported by
-
JDK-8287795 JavaFX WebView memory leak via EventListener
- Resolved
-
JDK-8289474 JavaFX WebView memory leak via EventListener
- Resolved
-
JDK-8292180 JavaFX WebView memory leak via EventListener
- Resolved
-
JDK-8292551 JavaFX WebView memory leak via EventListener
- Resolved
-
JDK-8287852 JavaFX WebView memory leak via EventListener
- Closed
- relates to
-
JDK-8315915 NPE thrown for event listeners after reloading page in a WebView
- Closed
- links to
-
Commit openjdk/jfx11u/24e053bb
-
Commit openjdk/jfx17u/cd39e0bb
-
Commit openjdk/jfx/f5348503
-
Review openjdk/jfx11u/105
-
Review openjdk/jfx17u/73
-
Review openjdk/jfx/799