0
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class HelloApplication extends Application {

    @Override
    public void start(Stage primaryStage) {
        HBox test = new HBox();
        Scene test2 = new Scene(test);
        primaryStage.setScene(test2);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Memory Usage from Task Manager

I'm don't really know if this is the usual amount of memory a blank javafx application uses and I find it quite a lot for a blank application. Tkinter programs seems to be use way less memory even with components inside the application. Is there a way to lower the amount of memory javafx uses in general?

Edit: enter image description here

Leo
  • 15
  • 7
  • Definitely not, it's unusual for it to take up so little memory, but I'm sure it'll get going once you add more functionality. If you're constrained by memory, forget java. – teapot418 Mar 11 '23 at 22:44
  • Note: the JVM tends to request more memory from the OS than it needs and is not too aggressive about freeing it because people get nervous when the garbage collector uses up too much CPU. If you want to see what your application really needs, you can experiment with lower values of `-Xmx` command line option. But this is not a very productive direction to explore. – teapot418 Mar 11 '23 at 22:52
  • Try a [profile](http://stackoverflow.com/q/2064427/230513) to see more details. – trashgod Mar 12 '23 at 00:13
  • When I start gedit, it uses 55 MB. Just something to consider. – VGR Mar 12 '23 at 00:28
  • @trashgod I'm not too sure what else I should include, but I included a few screenshots regarding heap memory – Leo Mar 12 '23 at 03:08
  • Java VM's like to reserve some memory for things to come (and basically the GC will initially run when you hit the max heap space. This is also why having virtual memory may be beneficial *even if you have a good amount of RAM*: you may have used memory sitting around doing nothing most of the time. You can alter some of the memory parameters using `-X` arguments for the `java` or `java.exe` VM. – Maarten Bodewes Mar 12 '23 at 03:10
  • @MaartenBodewes I've tried -Xmx and it doesn't really seem to affect how much memory it uses – Leo Mar 12 '23 at 03:26
  • You could use GraalVM to aot compile to native if you wished. I don’t know if this would decrease memory usage as opposed to running in a VM, but I guess it would. It seems surprising to me that -X memory options were unable to reduce [max memory usage](https://stackoverflow.com/questions/1493913/how-to-set-the-maximum-memory-usage-for-jvm) for you, but I’ll trust your findings on your platform. – jewelsea Mar 12 '23 at 04:46
  • This [example](https://stackoverflow.com/a/45124503/230513) illustrates using the -X options to an artificially small heap. What happens when you request garbage collection? – trashgod Mar 12 '23 at 13:20

0 Answers0