JDK-8163252 : JavaFx WebView uses too much heap for web pages with lots of images
  • Type: Bug
  • Component: javafx
  • Sub-Component: web
  • Affected Version: 8u91
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows
  • CPU: x86
  • Submitted: 2016-08-05
  • Updated: 2021-10-13
  • Resolved: 2016-08-09
Related Reports
Duplicate :  
Description
If you go to a web page with many images, JavaFx WebView uses way too much heap to load the web page.

For example, this particular web page has 340 images:

https://github.com/d3/d3/wiki/Gallery

JavaFx WebView takes around 6.7 GB of heap in order to render the page.
Firefox takes around 500 MB.

Here are some example heap overflow stacks if you only set you heaps to 2 GB or so:

{code}
Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space
        at com.sun.javafx.iio.gif.GIFImageLoader2.decodePalette(GIFImageLoader2.java:323)
        at com.sun.javafx.iio.gif.GIFImageLoader2.load(GIFImageLoader2.java:234)
        at com.sun.javafx.iio.ImageStorage.loadAll(ImageStorage.java:364)
        at com.sun.javafx.iio.ImageStorage.loadAll(ImageStorage.java:274)
        at com.sun.javafx.webkit.prism.WCImageDecoderImpl.loadFrames(WCImageDecoderImpl.java:173)
        at com.sun.javafx.webkit.prism.WCImageDecoderImpl.loadFrames(WCImageDecoderImpl.java:186)
        at com.sun.javafx.webkit.prism.WCImageDecoderImpl.addImageData(WCImageDecoderImpl.java:109)
        at com.sun.webkit.network.URLLoader.twkDidFinishLoading(Native Method)
        at com.sun.webkit.network.URLLoader.notifyDidFinishLoading(URLLoader.java:838)
        at com.sun.webkit.network.URLLoader.lambda$didFinishLoading$98(URLLoader.java:829)
        at com.sun.webkit.network.URLLoader$$Lambda$314/1527838714.run(Unknown Source)
        at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
        at com.sun.javafx.application.PlatformImpl$$Lambda$179/203274438.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
        at com.sun.javafx.application.PlatformImpl$$Lambda$178/1044483803.run(Unknown Source)
        at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
        at com.sun.glass.ui.win.WinApplication$$Lambda$167/1747735167.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:745)
{code} 
Comments
Please file a new Enhancement request to improve memory usage, since it seems we need more memory than Firefox for many images (~ 2 GB versus 500 MB). We are unlikely to have time to address this for JDK 9, though. I do note that the Java memory usage model is such that if you allocate a large heap, then garbage collection will take that into account and not run the garbage collector as aggressively, so I do not consider the fact that it grows to 6.7 GB with an 8 GB heap to be a bug or problem.
02-09-2016

We tried it out with 1.8.0_112-ea and its better, but still a problem. We cannot get the heap overflow with 2 GB on that page anymore so that is an improvement, butweI still get heap overflow with 1 GB heap. When heap set to 8GB, we still see the java process getting to 5.7 GB in size. This is still over ten times the size of our firefox test. Here is the overflow exception backtrace: Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space at com.sun.javafx.iio.gif.GIFImageLoader2.decodePalette(GIFImageLoader2.java:323) at com.sun.javafx.iio.gif.GIFImageLoader2.load(GIFImageLoader2.java:234) at com.sun.javafx.iio.ImageStorage.loadAll(ImageStorage.java:364) at com.sun.javafx.iio.ImageStorage.loadAll(ImageStorage.java:274) at com.sun.javafx.webkit.prism.WCImageDecoderImpl.loadFrames(WCImageDecoderImpl.java:179) at com.sun.javafx.webkit.prism.WCImageDecoderImpl.loadFrames(WCImageDecoderImpl.java:192) at com.sun.javafx.webkit.prism.WCImageDecoderImpl.getImageFrame(WCImageDecoderImpl.java:292) at com.sun.javafx.webkit.prism.WCImageDecoderImpl.getFrame(WCImageDecoderImpl.java:251) at com.sun.webkit.WebPage.twkUpdateContent(Native Method) at com.sun.webkit.WebPage.updateDirty(WebPage.java:296) at com.sun.webkit.WebPage.updateContent(WebPage.java:615) at com.sun.javafx.sg.prism.web.NGWebView.update(NGWebView.java:74) at javafx.scene.web.WebView.handleStagePulse(WebView.java:999) at javafx.scene.web.WebView.lambda$new$29(WebView.java:280) at javafx.scene.web.WebView$$Lambda$257/31349198.pulse(Unknown Source) at com.sun.javafx.tk.Toolkit.lambda$runPulse$30(Toolkit.java:355) at com.sun.javafx.tk.Toolkit$$Lambda$280/1609529788.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.tk.Toolkit.runPulse(Toolkit.java:354) at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:378) at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:510) at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:490) at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$404(QuantumToolkit.java:319) at com.sun.javafx.tk.quantum.QuantumToolkit$$Lambda$171/463039962.run(Unknown Source) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191) at com.sun.glass.ui.win.WinApplication$$Lambda$167/2002871171.run(Unknown Source) at java.lang.Thread.run(Thread.java:745)
02-09-2016

I tried on 8u102 with 2G java heap space(-Xmx2G), couldn't reproduce the issue, but issues is seen with 8u91 with the same 2G limit.
09-08-2016

Please also refer to attached javaFX program.
05-08-2016

I believe that this is a duplicate of JDK-8153148. Assign to Arunprasad to confirm. I note that I can reproduce the problem with 8u92, but not with 8u112-b01 and not with the latest 9-ea build. I haven't yet tried with 8u102.
05-08-2016

Can you please try this with 8u102? We have made some improvements in image loading, specifically to defer loading images until they are actually needed, which may address this. See JDK-8153148.
05-08-2016