显示 Java 虚拟机中的空闲内存量
为了显示 Java 虚拟机中的可用内存,我们使用 freeMemory() 方法。它是 java.lang.Runtime 类的某个方法。它返回 Java 虚拟机中的可用内存。如果我们调用 gc 方法,则有可能增加可用内存。
声明——java.lang.Runtime.freeMemory() 方法的声明如下——
public long freeMemory()
我们来看一个程序,用来显示 Java 虚拟机中的可用内存——
示例
public class Example {
public static void main(String[] args) {
// print statement at the start of the program
System.out.println("Start...");
// displays the free memory
System.out.println("" + Runtime.getRuntime().freeMemory());
}
}输出
Start... 15732848
© .
All rights reserved.
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP