Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8127144

WebView Memory leak and Crash VM

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 7u6
    • fx2.0.2, fx2.1
    • javafx
    • Windows 7 Home 32bit w/ JDK 1.7.0_2 and JavaFX 2.0.2
      Windows XP Professtional 32bit w/ JDK 1.6.0_31 and JavaFX 2.0.2
      Windows XP Professtional 32bit w/ JDK 1.6.0_31 and JavaFX 2.1.0 Developer preview (January 23, 2012)

    • web

      WebEngine#load and WebEngine#loadContents have memory leak problem.

      I call these method repeatedly. JVM's Private Working Set increase to over 1GB and then crash VM.
      JVM Memory (Heap and Non Heap) seems have no problems.

      I can always reproduce problem when I run below code.
      {code}
      package ex;

      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.TextField;
      import javafx.scene.layout.BorderPane;
      import javafx.scene.layout.HBox;
      import javafx.scene.web.WebEngine;
      import javafx.scene.web.WebView;
      import javafx.stage.Stage;

      public class Main extends Application {

      public static void main(String[] args) {
      launch(args);
      }

      WebView browser;
      WebEngine engine;
      TextField urlField;
      Button loadButton;

      int i = 0;

      String[] urls = new String[] {
      "http://www.google.co.jp",
      "http://www.yahoo.co.jp",
      "http://jp.msn.com",
      "http://www.goo.ne.jp",
      "http://www.facebook.com",
      "http://twitter.com",
      "http://www.yahoo.com",
      "http://en.wikipedia.org",
      "http://www.disney.co.jp",
      "http://www.hotpepper.jp/A_30300/svcSA11.html",
      "http://tabelog.com",
      "http://www.nttdocomo.co.jp/",
      };

      @Override
      public void start(Stage stage) throws Exception {
      urlField = new TextField();
      urlField.setMinWidth(480);
      loadButton = new Button("Go");
      loadButton.setOnAction(onButtonClicked);
      HBox pane = new HBox();
      pane.getChildren().addAll(urlField, loadButton);

      browser = new WebView();
      engine = browser.getEngine();
      BorderPane parent = new BorderPane();
      parent.setCenter(browser);
      parent.setBottom(pane);

      Scene scene = new Scene(parent, 640, 480);
      stage.setScene(scene);
      stage.show();

      new Thread(new Runnable() {

      @Override
      public void run() {
      while (true) {

      Platform.runLater(new Runnable() {
      @Override
      public void run() {
      engine.load(urls[i]);
      }
      });

      try {
      Thread.sleep(5000);
      } catch (InterruptedException e) {}
      i++;
      if (i > urls.length) i = 0;
      }
      }
      }).start();
      }

      EventHandler<ActionEvent> onButtonClicked = new EventHandler<ActionEvent>() {

      @Override
      public void handle(ActionEvent event) {
      String url = urlField.getText();
      engine.load(url);
      }

      };

      }

      {code}

        1. jconsole1.png
          jconsole1.png
          105 kB
        2. Main.java
          2 kB
        3. hs_err_pid3700.log
          16 kB
        4. jconsole2.png
          jconsole2.png
          92 kB
        5. stdout.txt
          250 kB

            peterz Peter Zhelezniakov
            mshibatajfx Manabu Shibata (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: