What is the exact meaning of Runtime.getRuntime().totalMemory()
来源:互联网 发布:数控雕刻机怎么编程 编辑:程序博客网 时间:2024/06/07 16:06
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 -Xmx
value.
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 fromtotalMemory()
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();
- What is the exact meaning of Runtime.getRuntime().totalMemory()
- What Is The Meaning of 0.0.0.0 In Routing Table?
- Runtime.getRuntime().maxMemory()/freeMemory()/totalMemory()
- Runtime.getRuntime().totalMemory() 数值一直不断增加
- what's the meaning of these numbers?
- what's the meaning of Shell?
- What's the meaning of EOF ?
- what's the meaning of BPM?
- what's the meaning of IFS
- What is the meaning of xmlns:tools in Android XML layout?
- What is time meaning......
- What's the meaning of the saturation arithmetic
- What 's the meaning of "Windows-on-Windows" layer?
- What's the meaning of x86 and x64 WoW?
- What is the use of "?
- What is meaning of run level in Linux system? What are they?
- CSDN, what's the meaning.
- What are the meaning of the items in the “alignment trap” error message?
- 服务降级及dubbo中的实现示例
- Android 彻底解决城区县三级联动问题(3D,2维)
- 操作系统基础知识
- 如何在Vim+Ctags+Taglist应用中添加自定义语言: systemverilog
- Linux系统下的51单片机数码管实现精准计时
- What is the exact meaning of Runtime.getRuntime().totalMemory()
- 查找一个字符串中子串出现的次数
- unityGUI简单滚动JS
- python字典中items()和iteritems()的区别
- iOS_地图大量标记
- 构造方法
- Andromeda OS 来了,Android 再见?
- super用法
- Web调用安卓,苹果手机摄像头,本地图片和文件