How to clear Javafx Webview memory usage after closing

I tried to create a user interface using webview in JavaFX, but there is one problem: when opening a large image using a pop-up, the memory usage is very large, and when the pop-up is closed, the memory usage does not drop, I see the memory usage through the Task Manager in Windows,

when an image with a size of about 8 MB was opened using web browsing, the memory reached 300 MB, I don’t understand why it is so big,

I tried

stage.setOnCloseRequest(new EventHandler<WindowEvent>() {

        @Override
        public void handle(WindowEvent event) { 
            webengine.load(null);   

        }
    });

but still do not free up memory

+4
source share
3 answers

, RT-33729 WebView WCImgDecoderImpl, Java 8u20. RT-33729 ( ) :

Webkit , -, . ( "" ) , , "", , . . Webkit:

http://trac.webkit.org/browser/trunk/Source/WebCore/loader/cache/MemoryCache.h

WCImgDecoderImpl JNI ImageSource, BitmapImage, CachedImage MemoryCache. , , WCImgDecoderImpl . WCImgDecoderImpl WebKit, . , WebKit WCImgDecoderImpl JNI. , WebView .

. WebView , ( ). ( , AWT), WebEngine .

, "about: blank" WebView; .

, , - , , , RT-35262 JVM - WebView/Webkit, Java 8u20 RT-34630 WebView JavaScript, - Java 9.

+7

( ), .

// Delete cache for navigate back
webEngine.load("about:blank");
// Delete cookies 
java.net.CookieHandler.setDefault(new java.net.CookieManager());
+3

, , . , , , JFXPanel. , , :

Scene scene = getScene();
jfxPanel.removeAll();
jfxPanel.setScene(scene);
WebView webView = (WebView) scene.getRoot();
webView.getWebEngine().load(url);

GetScene() ( Webview WebEngine), , JFXPanel . , , URL.

0
source

Source: https://habr.com/ru/post/1540629/


All Articles