Mr.Zeiss
Mr.Zeiss

Reputation: 159

Why an executable jar when run from a command line uses much more ram, than the same project run from Eclipse?

Why an executable jar when run from a command line uses much more RAM - in my case around 7 time more - than the same project run from Eclipse?

While developing the project I run the application from Eclipse (Run->Run) it used around 60mb (I looked at the just created javaw.exe process) of ram, whereas if I create an executable JAR and run it from command line (Windows) the ram usage is about 450mb. Also, the amplitude of ram usage change is more when run from the command line, than from Eclipse's Run->Run.

Upvotes: 6

Views: 1610

Answers (2)

Festus Tamakloe
Festus Tamakloe

Reputation: 11310

In eclipse it has to share the ram with other services/application. But on command line it has no restriction. On command line you have also the possibility to limit ram by launching the application. You can limit it by doing this

java -Xmx256M -Xms256M -cp /*.jar

Upvotes: 2

Tom
Tom

Reputation: 16198

This is probably to do with the JVM settings that Eclipse launches the application with. When launching the Jar, Java will make a best guess at what settings to use in terms of memory. You can change the size of the memory used with the the java command on the console:

java -Xms64m -Xmx256m -cp your.jar

-Xms??m sets the minimum heap size in mb.
-Xmx??m sets the maximum heap size in mb.

Java is probably automatically choosing a larger heap size automatically as it is not being dictated by eclipse.

Upvotes: 3

Related Questions