What is the exact meaning of Runtime.getRuntime().totalMemory()
2016-11-26 19:53
585 查看
来源:
http://stackoverflow.com/questions/3571203/what-is-the-exact-meaning-of-runtime-getruntime-totalmemory-and-freememory
http://stackoverflow.com/questions/3571203/what-is-the-exact-meaning-of-runtime-getruntime-totalmemory-and-freememory
According to the API totalMemory() Returns the total amount of memory in the Java virtual machine. The value returned by this method may vary over time, depending on the host environment.Note that the amount of memory required to hold an object of any given type may be implementation-dependent. maxMemory() Returns the maximum amount of memory that the Java virtual machine will attempt to use. If there is no inherent limit then the value Long.MAX_VALUE will be returned. freeMemory() Returns the amount of free memory in the Java Virtual Machine. Calling the gc method may result in increasing the value returned by freeMemory. In reference to your question, maxMemory()returns the -Xmxvalue. You may be wondering why there is a totalMemory() AND a maxMemory(). The answer is that the JVM allocates memory lazily. Lets say you start your Java process as such: java -Xms64m -Xmx1024m Foo Your process starts with 64mb of memory, and if and when it needs more (up to 1024m), it will allocate memory. totalMemory()corresponds to the amount of memory currently available to the JVM for Foo. If the JVM needs more memory, it will lazily allocate it up to the maximum memory. If you run with -Xms1024m -Xmx1024m, the value you get from totalMemory()and maxMemory()will be equal. Also, if you want to accurately calculate the amount of used memory, you do so with the following calculation : final long usedMem = totalMemory() - freeMemory(); |
相关文章推荐
- android.util.AndroidRuntimeException Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? com.uethinking.microvideo.manag
- What Is The Meaning of 0.0.0.0 In Routing Table?
- What is the meaning of the word logits in TensorFlow?
- What is the advantage of load() vs get() in Hibernate?
- Momma always said: "Life is like a box of chocolates, Forrest. You never know what you're gonna get."
- What is the location of the directory of C header files that match your running kernel?
- What Is the Purpose of This Book?
- what is the mean of "GPRINT Type" in cacti
- [Drupal] How to get the real path of a node, no matter it is a path or a url alias
- What 's the meaning of "Windows-on-Windows" layer?
- What is the location of the directory of C header files that match your running kernel?
- What do you think is the role of parents in preventing crime amongst young people?
- Life is like a box of chocolates. You never know what you're gonna get
- What is the maximum amount of memory any single process on Windows can address? Is this different than the maximum virtual memor
- What is the maximum length of a URL
- Life is like a box of chocolates, you never know what you’re gonna get.
- What is the key of Data Assimilation?
- Programming Basic--what is the output of the following code?
- What is the easiest way of getting OpenLayers to configure itself for printing?
- opensuse 11.3--安装vmware tools 【What is the location of the directory of C header files that match your running】已解决