I'm facing a severe problem with JavaFX under Linux. Maybe someone knows a solution or a workaround:
Symptom:
- Running a JavaFx application under Linux causes Xorg Resource Leaks and as a consequence increasing CPU load by the Java process and by the process Xorg.
- The resource leak can be observed using the Linux tool xrestop.
- When stopping the application the resources are freed and the CPU load of the Xorg process is normal.
Tested Linux Versions:
- Debian 8.5 (64 bit),
- Ubuntu 15.10 and 16.04 (64 bit and 32 bit)
- Manjaro (64 bit)
Tested Hardware:
- Intel CPU and Intel CPU graphics,
- Intel CPU and AMD graphic card.
Tested JDK: Oracle JDK 8.91, OpenJDK 1.8.0_91 and OpenJfx 8.
On Windows machines the JavaFx applications run without problems. Even on a Linux guest running in VmWare under a windows host, the JavaFx applications run without a resource leak.
The resource leak appears on every change on the GUI, even if you use constants objects and change the visibility of these objects.
Sample program to reproduce the leak:
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import javafx.util.Duration;
public class HelloWorld extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage stage) {
Label lblTick = new Label("Tick");
GridPane pane = new GridPane();
pane.add(lblTick, 0, 0);
KeyFrame kf = new KeyFrame(Duration.millis(100),
e -> lblTick.setVisible(!lblTick.isVisible()));
Timeline tl = new Timeline(kf);
tl.setCycleCount(Animation.INDEFINITE);
tl.play();
Scene scene = new Scene(pane, 30, 30);
stage.setScene(scene);
stage.show();
}
}
Any help is appreciated.
I found the cause for this bug and a workaround:
- The cause is a buggy hardware graphics acceleration for Linux.
- The workaround is to start the JavaFx application with parameter -Dprism.order=sw
The bug is also included in JDK 9.
I reported this as a bug to Oracle.