• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Regarding memory allocated to JVM

 
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.
 
Bartender
Posts: 9615
16
Mac OS X Linux 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.
 
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.
     
    Nothing? Or something? Like this tiny ad:
    Thread Boost feature
    https://coderanch.com/t/674455/Thread-Boost-feature
      Bookmark Topic Watch Topic
    • New Topic