环境:jdk1.8 虚拟机参数:-verbose:gc -XX:+PrintGCDetails -Xmx20m -Xms20m -Xmn10m -XX:SurvivorRatio=8 -XX:+HeapDumpOnOutOfMemoryError
能够看出,eden占8M却放不下6M数据,发生了一次Ygc.gc信息以下spa
[GC (Allocation Failure) [PSYoungGen: 6750K->936K(9216K)] 6750K->5040K(19456K), 0.0193742 secs] [Times: user=0.00 sys=0.02, real=0.03 secs] Heap PSYoungGen total 9216K, used 3150K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000) eden space 8192K, 27% used [0x00000000ff600000,0x00000000ff8298d8,0x00000000ffe00000) from space 1024K, 91% used [0x00000000ffe00000,0x00000000ffeea020,0x00000000fff00000) to space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000) ParOldGen total 10240K, used 4104K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000) object space 10240K, 40% used [0x00000000fec00000,0x00000000ff002020,0x00000000ff600000) Metaspace used 3497K, capacity 4498K, committed 4864K, reserved 1056768K class space used 387K, capacity 390K, committed 512K, reserved 1048576K
新生代由原来的6750K 变成936K ,新生代总大小为 9216K, 使用的堆空间由6750K 变成5040K ,总大小为 19456(19M),耗时0.0193742秒code
原先的4m数据进入了老年代,1m在from区,1m在eden区blog
有些咱们看不到的东西占了 6750-4*1024=2654K(2.5M)。Ygc后这些东西就释放了ci