I have a couple of simple applications written in java, one of them written to act as a widget. What surprised me how much RAM even small applications use.
I wrote the following to see if it is a bug in my programs, or a general Java issue:
public class ram {
public static void main(String[] args){
while(true)System.out.print("Hello World");//while loop to give me time to check RAM usage
}
}
Then compiled and ran it with java ram
and it gave me the following RAM usage:
The process java (with pid 4489) is using approximately 43.3 MB of memory.
34460 KB [heap]
7088 KB /usr/lib/jvm/java-7-openjdk/jre/lib/amd64/server/libjvm.so
1712 KB /usr/lib/jvm/java-7-openjdk/jre/lib/rt.jar
136 KB [stack:4495]
120 KB /usr/lib/jvm/java-7-openjdk/jre/lib/amd64/libjava.so
Isn't this too high? Especially a heap of 34MB. My system is ArchLinux x86_64 and openjdk-7.
Is there any way to minimise the amount of RAM used by the JVM?
Edit: I tried using the -Xmx flag and this is what I got (1281k was the smallest it would let me start with):
java -Xmx1281k ram
The process java (with pid 4987) is using approximately 27.6 MB of memory.
18388 KB [heap]
For comparison, Python2 uses 4.4MB, Mono uses 4.3MB.