Hi all! I've got some confusion... My JVM shows a total memory of 2MB once, and once it shows 4MB and even 5MB or 6MB at times(I have not made any explicit extensions to the JVM using -Xmx or -Xms). I would like to know if there is any limit on the memory allocated to a JVM without any explicit settings made by the user and , I would also like to know the mechanism how memory is allocated to the JVM.
Total Memory and (Runtime.getRuntime().totalMemory())
Free Memory (Runtime.getRunTime().freeMemory())
The first is the maximum memory the JVM can ask to the OS before an OutOfMemoryError happens. You can change that with the command line parameters of java o javaw
The second is the total amount of memory of that is allocated at this moment. Because the JVM does not allocate all memory just because you said in the command line parameters that you might use it all.
The third is the amount of memory that is free from the total allocated memory.
You can test this by enably the gc statics in the command line and you will see what the garbage collector does when the VM needs to allocate more and ask it to the OS, but it will nos ask more than what you specified for maximum memory parameter.