案例:
垃圾回收后,内存占用仍然很高。
执行GC之后,堆内存只释放了30M左右。
查看代码发现错误:
/** * 演示查看对象个数 堆转储 dump */ public class Demo1_13 { public static void main(String[] args) throws InterruptedException { List<Student> students = new ArrayList<>(); for (int i = 0; i < 200; i++) { students.add(new Student()); // Student student = new Student(); } Thread.sleep(1000000000L); } } class Student { private byte[] big = new byte[1024*1024]; }