JDK-8117172 : Memory leak with Animated images
  • Type: Bug
  • Component: javafx
  • Sub-Component: scenegraph
  • Affected Version: fx2.0.2
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2012-01-26
  • Updated: 2015-06-17
  • Resolved: 2013-03-12
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 8
8Fixed
Related Reports
Blocks :  
Duplicate :  
Duplicate :  
Duplicate :  
Description
Run attached application and look at memory usage.

It looks like gif is animated with some thread. And this thread have strong reference to image.
Thus, when image become out of scene, one link remains ... in mentioned thread. And this prevents GC from collecting those images.
Comments
ok, close as verified on b104
29-08-2013

I also tested with my sample code from RT-28782: With JavaFX 2.2: OutOfMemoryError after a few iterations. With JavaFX 8: No error. Memory stays low after 1000+ iterations.
29-08-2013

I retested it with more that 3000 iterations. In live heap there were no objects with more than 360 instances after each GC I tried during testing and the used heap didn't grow. Without the fix I would have hit OutOfMemory error after probably few hundred iterations.
29-08-2013

Changeset: d45b7c33204d Author: Lubomir Nerad <lubomir.nerad@oracle.com> Date: Tue Mar 12 12:15:28 2013 +0100 URL: http://jfxsrc.us.oracle.com/javafx/8.0/scrum/graphics/rt/rev/d45b7c33204d Description: Fix for RT-19239: Memory leak with Animated images
12-03-2013

I have found the same leak. Here is a bit of code that you can use for analysis: @Override public void start(Stage primaryStage) { try { final BorderPane frm = new BorderPane(); frm.setLeft(ButtonBuilder.create().text("gif").onAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent t) { try (InputStream strm = getClass().getResourceAsStream("/path/to/gif")) { ImageView iv = new ImageView(new Image(strm)); frm.setCenter(iv); } catch (Exception ex) { } } }).build()); frm.setRight(ButtonBuilder.create().text("png").onAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent t) { try (InputStream strm = getClass().getResourceAsStream("/path/to/png")) { ImageView iv = new ImageView(new Image(strm)); frm.setCenter(iv); } catch (Exception ex) { } } }).build()); primaryStage.setScene(SceneBuilder.create().root(frm).width(800).height(600).build()); primaryStage.show(); } catch (Exception ex) { Log.exc(ex); } } If you keep clicking the gif button, force GC from visualvm, you can see a strict increase of memory, according to visualvm some byte arrays are referenced just as explained in the above comments. My environment is Lubuntu 12.04, oracle jdk 1.7.0_07 (downloaded within the netbeans bundle) Do you guys see any future date by which this would be fixed? Thank you! Jozsef
24-02-2013

The leak depends on the size of the GIF image. I have asked Joe to provide more detail about the leak, including the conditions under which it occurs. Note that this is not a regression and has been present since at least JavaFX 2.0.
10-07-2012

PM: What is the extent of memory leak - how many bytes ? Does the total amount leaked increase (over time) as the animation happens ?
04-07-2012

The Image object itself sets up the Timeline using the frame data supplied by the loader, so this will need to be fixed in Image.
27-06-2012

it is animation bug, GIF loader can not do anything here itself
25-06-2012

ok / sqe
12-03-2012

Too late to fix this in 2.1. Also the impact is limited to animated GIFs. We will address this for 2.2.
01-03-2012