When to use Runtime.maxMemory () and totalMemory ()

What is the difference between Runtime.maxMemory()and Runtime.totalMemory()? Javadoc is pretty vague in this regard (for me).

What are typical use cases for these two methods, that is, when it would be inappropriate to use the corresponding other?

+5
source share
4 answers

totalMemory()returns the amount of memory that is currently in use, and maxMemory()indicates how much the JVM can allocate in total.

Note: this implies: totalMemory() <= maxMemory()and you can also get "how much memory is left"maxMemory() - totalMemory()

, , , totalMemory() . : , .

+6

- , JVM. . - , JVM. .

+5

MaxMemory() - , Xmx

+3

totalMemory(), JVM, , , . javadoc, totalMemory(), . JVM totalMemory JVM

JVM. Jvm totalMemory() . maxMemory() unles java.lang.OutOfMemoryError.

0

All Articles