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

[WebView] Memory created by javascript object are never reclaimed after closing the window

    Details

    • Subcomponent:
      web

      Description

      The issue is that when javascript objects are created and stored in global context (window). After the window is closed. The memory of the process doesn't decrease and grow making the application slow and crashing. (In the sample provided bellow the application is not crashing, but our real application is)

      Might be linked to RT-30354, mark as resolved, but not fixed in this context.
      Also might be linked to RT-35262.

      This has been tested in the latest version of java8 b123. But It also occurs in Java8 b96 and Java7u45.

      This issue can be reproduce easily with the sample provided and the following steps :
      1) Open the application.
      2) Click on "Open new Window" link multiple time.
      3) Close all newly created window.
      4) Observe that the memory allocated for the process is not reclaimed.

      I hope this is helping resolving memory leak issues.

      ############## MainWindow.java ###########################

      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.geometry.HPos;
      import javafx.geometry.VPos;
      import javafx.scene.Scene;
      import javafx.scene.control.Hyperlink;
      import javafx.scene.layout.HBox;
      import javafx.scene.layout.Region;
      import javafx.scene.paint.Color;
      import javafx.scene.web.WebEngine;
      import javafx.scene.web.WebView;
      import javafx.stage.Stage;


      public class MainWindow extends Application {

      @Override
          public void start(Stage stage) {
           create(stage);
          }
          
          public static void create(Stage stage) {
              // create the scene
              stage.setTitle("Web View");
              Scene scene = new Scene(new Browser(), 750, 500, Color.web("#666970"));
              stage.setScene(scene);
              stage.show();
          }
       
          public static void main(String[] args){
              launch(args);
          }

      }

      class Browser extends Region {

          final WebView browser = new WebView();
          final WebEngine webEngine = browser.getEngine();
          final HBox toolBar = new HBox();
           
          public Browser() {
              //apply the styles
              getStyleClass().add("browser");
              // load the web page
              webEngine.load(Browser.class.getResource("test.html").toExternalForm());
              
              final Hyperlink hpl = new Hyperlink("Open new Window");
       
              hpl.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent e) {
                   MainWindow.create(new Stage());
                  }
              });
              
              toolBar.getChildren().add(hpl);
              
              getChildren().add(toolBar);
              getChildren().add(browser);
          }

          @Override protected void layoutChildren() {
              double w = getWidth();
              double h = getHeight();
              double tbHeight = toolBar.prefHeight(w);
              layoutInArea(browser,0,0,w,h-tbHeight,0, HPos.CENTER, VPos.CENTER);
              layoutInArea(toolBar,0,h-tbHeight,w,tbHeight,0,HPos.CENTER,VPos.CENTER);
          }
       
          @Override protected double computePrefWidth(double height) {
              return 750;
          }
       
          @Override protected double computePrefHeight(double width) {
              return 500;
          }
      }

      ############## test.html ###########################

      <html>
      <head>
      </head>
      <body>
      <script>
      function A() {
      this.a = {};
      for (var i = 0; i <= 1000; i++) {
      this.a[i] = function(j) {
      return j + 10;
      };
      }
      }

      objects = [];
      for (var i = 0; i <= 1000; i++) {
      objects.push(new A());
      }
      </script>
      </body>
      </html>


        Attachments

          Activity

            People

            • Assignee:
              ghb Guru Hb
              Reporter:
              duke J. Duke (Inactive)
            • Votes:
              2 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Imported: