-
Bug
-
Resolution: Fixed
-
P2
-
8, 9
-
Win 7 Professional x64, jdk-8-u31x64
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8151741 | 8u102 | Murali Billa | P2 | Closed | Fixed | b01 |
JDK-8159107 | 8u92 | Murali Billa | P2 | Resolved | Fixed | b33 |
Here is some example code with a large long[] array that takes about 80MB of RAM so the leak is easy to spot in jvisualvm:
package bugreports;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.concurrent.Worker;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import netscape.javascript.JSObject;
public class WebEngineNotReleasingMemory extends Application
{
static final String html = "<!DOCTYPE html>" +
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-16\">" +
"<html>" +
"<button type=\"button\" onClick=\"javaCallback.sayWorld()\">Hello</button>" +
"</html>";
public static final class CallbackView extends BorderPane
{
private final long[] memoryWaster = new long[10000000];
private final WebView view = new WebView();
public CallbackView()
{
view.getEngine().getLoadWorker().stateProperty().addListener((ov, o, n) -> {
if (n == Worker.State.SUCCEEDED)
{
final JSObject window = (JSObject) view.getEngine().executeScript("window");
assert window != null;
window.setMember("javaCallback", this);
}
});
view.getEngine().loadContent(html);
setCenter(view);
}
// called from JavaScript
public void sayWorld()
{
System.out.println("World!");
}
}
@Override
public void start(final Stage primaryStage) throws Exception
{
Platform.setImplicitExit(false);
final CallbackView pane = new CallbackView();
primaryStage.setScene(new Scene(pane));
primaryStage.show();
}
}
How to reproduce:
1) Run the application
2) Close the window
3) Connect with jvisualvm to the application and force garbage collection, memory is not being reclaimed
- backported by
-
JDK-8159107 WebView leaks memory when containing object acts as javascript callback handler
- Resolved
-
JDK-8151741 WebView leaks memory when containing object acts as javascript callback handler
- Closed
- duplicates
-
JDK-8170085 Javafx Webengine JSObect members working inconsistently
- Closed
-
JDK-8170515 WebView. "onclick" attribute in HTML not working on Windows with Java 8u111.
- Closed
-
JDK-8149707 WebView leaks memory when containing object acts as javascript callback handler
- Closed
-
JDK-8089776 WebView memory leak when JavaScript callbacks are assigned.
- Closed
- relates to
-
JDK-8152737 Crash in RuntimeObject::put when object passed to JSObject::setMember is GCed
- Resolved
-
JDK-8151459 Validation of new behaviour for JS callback memory leak
- Resolved
-
JDK-8154127 Need to document that JavaScript to Java bindings use weak references
- Resolved
-
JDK-8167098 Backport of JDK-8158926 to JDK 8u mistakenly used preliminary patch
- Resolved
-
JDK-8169341 Broken JavaScript-to-Java callback in WebEngine with 2nd call
- Open
-
JDK-8172954 Memory Leak test case (non-UI) for JDK-8089681
- Open
-
JDK-8169204 Need to document JSObject Call and setSlot APIs to use weak references
- Resolved
-
JDK-8168625 Java WebView communication between java and javascript fails in Java 8 U112
- Closed
-
JDK-8149707 WebView leaks memory when containing object acts as javascript callback handler
- Closed
-
JDK-8165302 Upcall from JavaScript to Java is broken
- Closed
-
JDK-8178878 [WebView] Java method not getting called from HTML
- Closed