• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regarding memory allocated to JVM  RSS feed

 
mr.a robertson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joe Ess
Bartender
Posts: 9443
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by mr.a robertson:

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 ,

According to the documentation for the java command, the default upper limit for VM memory allocation is 64Meg.


I would also like to know the mechanism how memory is allocated to the JVM.

The virtual machine requests memory from the operating system through the OS's API with a call like malloc.
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are three concepts:

  • Maximum Memory (Runtime.getRuntime().maxMemory())
  • 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.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!