Runtime memory methods and -Xmx/Xms?

F

Frank D. Greco

In the 1.4.2 java.lang.Runtime class, there are 3 methods that
return memory values:

totalMemory(), freeMemory() and maxMemory()

[maxMemory() seems to be new for 1.4.2]

The javadocs say:

totalMemory() - total amount of memory in the JVM... the total amount of
memory currently available for current and future objs.
maxMemory() - max amount of memory that the JVM will attempt to use.
freeMemory() - free heap memory in the JVM.

What is the difference between maxMemory() and totalMemory()? And why
does "-XmxNNNN" increase the value of maxMemory() but not totalMemory()?

Thanks,

Frank

+=========================================+
| Crossroads Technologies Inc. |
| Enterprise Java Engineering |
| Web: www.CrossroadsTech dot com |
| Email: fgreco @ crossroadstech dot com |
+=========================================+
 
D

dhek bhun kho

Hey Frank

Thu said:
In the 1.4.2 java.lang.Runtime class, there are 3 methods that
return memory values:

totalMemory(), freeMemory() and maxMemory()

[maxMemory() seems to be new for 1.4.2]

The javadocs say:

totalMemory() - total amount of memory in the JVM... the total amount of
memory currently available for current and future objs.
maxMemory() - max amount of memory that the JVM will attempt to use.
freeMemory() - free heap memory in the JVM.

What is the difference between maxMemory() and totalMemory()? And why
does "-XmxNNNN" increase the value of maxMemory() but not totalMemory()?

Thanks,

Frank

totalMemory() is the current amount of memory that the JVM has allocated
natively. When the memory demand exceeds the available memory even after a
garbage collection, and the -Xmx setting has not been exceeded, then the
JVM will allocate some extra memory for the objects in the JVM.
totalMemory is a 'soft' upper limit. The maxMemory() is an 'hard upper'
limit.

The figures returned by these method calls aren't very useful except for
some rough benchmarking and such. You're better off using a profiler. (I
recommend JProfiler, too bad they haven't got a cheaper license, although
it surely looks and works perfectly; maybe we can get a license for 50
euros a piece if we can get 1000 orders for them).

Greets
Bhun.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top