long totalMemory()
描述 (Description)
java.lang.Runtime.totalMemory()方法返回Java虚拟机中的总内存量。 此方法返回的值可能会随时间而变化,具体取决于主机环境。 请注意,保存任何给定类型的对象所需的内存量可能与实现有关。
声明 (Declaration)
以下是java.lang.Runtime.totalMemory()方法的声明
public long totalMemory()
参数 (Parameters)
NA
返回值 (Return Value)
此方法不返回值。
异常 (Exception)
NA
例子 (Example)
以下示例显示了lang.Runtime.totalMemory()方法的用法。
package com.iowiki;
public class RuntimeDemo {
public static void main(String[] args) {
// print the state of the program
System.out.println("Program is starting...");
// print the total memory
System.out.println("" + Runtime.getRuntime().totalMemory());
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
Program is starting...
63111168