I am using a 64-bit Linux machine (8 GB of RAM) in KDE with Eclipse as my IDE. I also use Oracle JDK. I made a little animation using JavaFX and a few shots on the Internet to revitalize the Earth orbiting the Sun. Whenever I run it, the animation works fine, but it constantly eats all the RAM on my computer until everything hangs. This usually takes less than 5 minutes.
package Practice;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
import javafx.animation.AnimationTimer;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class BasicAnimation extends Application {
public BasicAnimation() {
}
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Orbit");
Group root = new Group();
Scene scene = new Scene(root);
primaryStage.setScene(scene);
Canvas canvas = new Canvas(512,512);
root.getChildren().add(canvas);
GraphicsContext gc = canvas.getGraphicsContext2D();
Image earth = new Image(getClass().getResourceAsStream("earth.png"), 25.0, 25.0 ,false, false);
Image sun = new Image(getClass().getResourceAsStream("sun.jpg"), 50.0, 50.0, false, false);
Image space = new Image(getClass().getResourceAsStream("space.jpg"));
final long startNanoTime = System.nanoTime();
new AnimationTimer() {
public void handle(long currentNanoTime) {
double t = (currentNanoTime - startNanoTime) / 1000000000.0 ;
double x = 232 + 128 * Math.cos(t);
double y = 232 + 128 * Math.sin(t);
gc.drawImage(space, 0, 0);
gc.drawImage(earth, x, y);
gc.drawImage(sun, 196, 196);
}
}.start();
primaryStage.show();
}
}
I installed -Xms512m, -Xmx512m and -Xss512m. Is there something I'm doing wrong that could be causing this, and could you explain why this is happening or how to avoid it?
Also, if something is wrong with my question, please let me know.
Edited: additional information added
2356x2356, 25x25px . 750x750, 50x50 . 1920x1080, 512x512 .
: https://www.thesun.co.uk/wp-content/uploads/2016/06/download.jpg?w=750&strip=all
: https://openclipart.org/image/2400px/svg_to_png/218125/3d-Earth-Globe.png
: http://www.gunnars.com/wp-content/uploads/2014/08/Space.jpg