I have some code that loads and displays multiple images one at a time. I am creating an Image from an input stream that represents an animated gif.
InputStream inputStream = new ByteArrayInputStream(animatedGifByteArray);
Image image = new Image(inputStream);
After the image is no longer used and discarded, the byte[] is never garbage collected. I don't even need to set the image in an ImageView.. the code above is enough to cause the issue.
VisualVM shows that the QuantumToolkit.animationRunnable field is the nearest GC root.
I've tried it in 2.0.2 and 2.1 b17.
It only appears to happen with animated gif files. Regular gif files don't seem to cause the problem.
Here's a simple code example. With a 70k animated gif file ("animated.gif"), this code will cause an OutOfMemoryError at about the 60th image (using JREs default max heap size).
I'm using JavaFX 2.1 b17 with JRE 1.6_30 on Windows 7.
public class ImageLeakTest extends Application {
public void start(Stage stage) throws Exception {
for (int i = 0; i < 100; i++) {
new Image("C:/animated.gif");
Thread.sleep(500);
}
}
public static void main(String[] args) {
Application.Launch(args);
}
}
InputStream inputStream = new ByteArrayInputStream(animatedGifByteArray);
Image image = new Image(inputStream);
After the image is no longer used and discarded, the byte[] is never garbage collected. I don't even need to set the image in an ImageView.. the code above is enough to cause the issue.
VisualVM shows that the QuantumToolkit.animationRunnable field is the nearest GC root.
I've tried it in 2.0.2 and 2.1 b17.
It only appears to happen with animated gif files. Regular gif files don't seem to cause the problem.
Here's a simple code example. With a 70k animated gif file ("animated.gif"), this code will cause an OutOfMemoryError at about the 60th image (using JREs default max heap size).
I'm using JavaFX 2.1 b17 with JRE 1.6_30 on Windows 7.
public class ImageLeakTest extends Application {
public void start(Stage stage) throws Exception {
for (int i = 0; i < 100; i++) {
new Image("C:/animated.gif");
Thread.sleep(500);
}
}
public static void main(String[] args) {
Application.Launch(args);
}
}
- duplicates
-
JDK-8117172 Memory leak with Animated images
-
- Closed
-