Reputation: 169
I have a small Java application which is basically a command line utility which sleeps 99% of the time and runs once a day to copy a file in particular location. That app takes in memory 10 Mb. Of course, that is not a big number, but it looks like that app takes more memory than it could. Could you suggest how to reduce the amount of memory for that app?
I run it like this:
java -Xmx12m -jar c:\copyFiles\copyFiles.jar
Upvotes: 1
Views: 574
Reputation: 120848
AFAIK this heavily depends on the Garbage Collector that is used and the jvm version, but in general the VM is not very eager to give memory back to the OS, for numerous reason. A much broader discussion is here about the same topic
Since jdk-12, there is this JEP :
http://openjdk.java.net/jeps/346
that will instruct the VM (with certain flags) to give memory back to the OS after a "planned" garbage collector cycle takes place - this is controlled by some newly introduced flags; read the JEP to find out more.
Upvotes: 2
Reputation: 5256
You are allowing your application to use roughly 12 MB because you use the -Xmx12m
parameter for the JVM. Java is a bit wasteful regarding memory. You can decrease the max amount of memory your application can use:
-Xmx10k
- Can use up to 10 KB of memory.
-Xmx10m
- Can use up to 10 MB of memory.
-Xmx10g
- Can use up to 10 GB of memory.
Feel free to mix this setting however you want but be careful. If you exceed the set amount an OutOfMemory-exception is thrown.
Upvotes: 1