I've run into a situation where a simple canvas Drawing app shows a gradual increase in physical Memory usage over time until it hits about 80% mark And tries to maintain the process memory usage around That number (that is the %MEM column when 'top' is run, 64bit Linux box). Of course by that point page swapping kicks in. I've tried to limit memory usage by using -Xmx10m -Xms10m and even -XX:+UseG1GC but nothing appears to make a difference. Just a side note, I've even tried the StockLineChartApp example shipped with oracle jdk Javafx examples and it displays a physical memory usage increase as well. I'm using jdk1.8.0_102.
Any feedback regarding this issue would be very helpful. Thanks.
//
package test8;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import javafx.util.Duration;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.animation.Animation;
public class Test8 extends Application {
GraphicsContext gc;
double x;
double y;
@Override
public void start(Stage primaryStage) {
try {
Group root = new Group();
Scene s = new Scene(root, 600, 400, Color.BLACK);
final Canvas canvas = new Canvas(500,300);
gc = canvas.getGraphicsContext2D();
root.getChildren().add(canvas);
Pane pane = new Pane();
pane.getChildren().add(root);
Scene scene = new Scene(pane);
primaryStage.setTitle("canvas test");
primaryStage.setScene(scene);
primaryStage.show();
gc.beginPath();
x = 0.0;
y = 0.0;
EventHandler onFinished = new EventHandler<ActionEvent>() {
public void handle(ActionEvent t) {
y = (y<canvas.getHeight()) ? (y + 10.0) : 0.0;
x = (x<canvas.getWidth()) ? (x + 5.0) : 0.0;
gc.lineTo(x,y);
gc.stroke();
if (x==0.0) gc.beginPath();
}
};
final Timeline timeline = new Timeline();
timeline.setCycleCount(Animation.INDEFINITE);
timeline.setAutoReverse(true);
timeline.getKeyFrames().add(new KeyFrame(Duration.millis(40), onFinished));
timeline.play();
} catch (Exception e) {
System.out.println("Application start Exception");
} finally {
}
}
public static void main(String[] args) {
launch(args);
}
}