我想要打印以下打印方法中使用的内存的代码
import java.*.*;
public static void main(String[] args)
{
System.out.println('The memory used is');
}
最佳答案
使用下面的代码
float mb = 1024*1024;
//Getting the runtime reference from system
Runtime runtime = Runtime.getRuntime();
System.out.println("##### Heap utilization statistics [MB] #####");
//Print used memory
System.out.println("Used Memory:"+ (runtime.totalMemory() - runtime.freeMemory()) / mb);
//Print free memory
System.out.println("Free Memory:"+ runtime.freeMemory() / mb);
//Print total available memory
System.out.println("Total Memory:" + runtime.totalMemory() / mb);
//Print Maximum available memory
System.out.println("Max Memory:" + runtime.maxMemory() / mb);
关于java - java中如何查看RAM中使用了多少内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24930342/