JDK-8159594 : The WebView component appears to leak memory
  • Type: Bug
  • Component: javafx
  • Sub-Component: web
  • Affected Version: 8u92
  • Priority: P3
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2016-06-03
  • Updated: 2016-07-20
  • Resolved: 2016-07-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9Resolved
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :


ADDITIONAL OS VERSION INFORMATION :
Tested on most Windows platforms from Vista upwards.

A DESCRIPTION OF THE PROBLEM :
We are trying to run a JavaScript based GUI inside a WebView but suffer from an apparent memory leak. Even the simplest code we can come up with appears to have this problem.

The test GUI side just alternates between two pages, as follows:

Page1:

  <head></head>
  <body>
    <h1>Page 1</h1>
    <script>window.location.href = "page2.html";</script>
  </body>

Page 2:

  <head></head>
  <body>
    <h1>Page 2</h1>
    <script>window.location.href = "page1.html";</script>
  </body>

The Java application is as follows:

import java.awt.Dimension;
import java.io.IOException;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.web.WebView;
import javax.swing.JFrame;

public class FXBrowser
{
  private final JFrame frame;

  public FXBrowser()
  {
    JFXPanel fxPanel = new JFXPanel();
    frame.add(fxPanel);
    Platform.runLater(() -> initFX(fxPanel));
    frame.pack();
    frame.setVisible(true);
  }

  private void initFX(JFXPanel fxPanel)
  {
    fxPanel.setScene(new Scene(createMainWebView()));
  }  
  
  private WebView createMainWebView()
  {
    WebView webComponent = new WebView();
    webComponent.getEngine().load("<url to above pages>");
    return webComponent;
  }
  
  public static void main() throws IOException
  {
    FXBrowser gui = new FXBrowser();
    System.in.read();
  }
}

Running this for just 5 minutes is enough to increase memory usage by a few hundred MB. Garbage collection appears unable to free anything up.

Note that we have also tested this with many versions of JavaFX from 1.8.0_66 onwards. 

There is also another user reporting a very similar problem here http://stackoverflow.com/questions/36266013/exploding-memory-usage-in-javafx-webview-while-loading-many-pages

Due to this behavior, we have decided to run our GUI inside a browser instead i.e. We are NOT waiting on a fix. I have raised this bug purely to document the fact that it was seen.

Please let me know if you need any further information. I will be happy to help.

Thanks,
Lee Perry

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Use the code examples in the description. Note you will need to enter the actual URL to wherever you save the GUI pages.


REPRODUCIBILITY :
This bug can be reproduced always.


Comments
This issue is no more reproducible in JDK 9 . Hence closing as "Can not reproduce".
20-07-2016