当我们定义一个Java类时,我们可以在堆中获取Obeject的内存使用情况,但是由于程序的未知行为,我们无法获取运行时的内存使用情况。例如下面的类:
public class Sample{
private int age;
private String name;
private static List scores = new ArrayList<Integer>();
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
scores.add(sc.nextInt());
}
}
}
那么我们如何获取类 Sample 的运行时内存使用情况呢?