个人随笔
目录
六、Eclipse测试堆内存抛出java.lang.OutOfMemoryError异常
2020-12-24 15:36:18

1、配置启动参数

VM arguments中加入如下内容:

  1. -verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8

2、测试代码

  1. public class TestOutOfMemoryError {
  2. static class OOMObject{}
  3. public static void main(String[] args) {
  4. System.out.println("TestOutOfMemoryError");
  5. List<OOMObject> list = new ArrayList<OOMObject>();
  6. while(true) {
  7. list.add(new OOMObject());
  8. }
  9. }
  10. }

3、运行

  1. TestOutOfMemoryError
  2. [GC (Allocation Failure) [DefNew: 8036K->1024K(9216K), 0.0140061 secs] 8036K->4733K(19456K), 0.0375589 secs] [Times: user=0.02 sys=0.00, real=0.04 secs]
  3. [GC (Allocation Failure) [DefNew: 9216K->1024K(9216K), 0.0176372 secs] 12925K->10815K(19456K), 0.0176841 secs] [Times: user=0.02 sys=0.00, real=0.02 secs]
  4. [GC (Allocation Failure) [DefNew: 9216K->9216K(9216K), 0.0000180 secs][Tenured: 9791K->5863K(10240K), 0.0464165 secs] 19007K->14432K(19456K), [Metaspace: 79K->79K(4480K)], 0.0468024 secs] [Times: user=0.05 sys=0.00, real=0.05 secs]
  5. [Full GC (Allocation Failure) [Tenured: 5863K->5863K(10240K), 0.0340768 secs] 14755K->14755K(19456K), [Metaspace: 79K->79K(4480K)], 0.0341092 secs] [Times: user=0.03 sys=0.00, real=0.03 secs]
  6. [Full GC (Allocation Failure) [Tenured: 5863K->5853K(10240K), 0.0377713 secs] 14755K->14745K(19456K), [Metaspace: 79K->79K(4480K)], 0.0378298 secs] [Times: user=0.03 sys=0.00, real=0.04 secs]
  7. Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
  8. at java.util.Arrays.copyOf(Arrays.java:3210)
  9. at java.util.Arrays.copyOf(Arrays.java:3181)
  10. at java.util.ArrayList.grow(ArrayList.java:261)
  11. at java.util.ArrayList.ensureExplicitCapacity(ArrayList.java:235)
  12. at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:227)
  13. at java.util.ArrayList.add(ArrayList.java:458)
  14. at com.suibibk.test.TestOutOfMemoryError.main(TestOutOfMemoryError.java:12)
  15. Heap
  16. def new generation total 9216K, used 8902K [0x04a00000, 0x05400000, 0x05400000)
  17. eden space 8192K, 100% used [0x04a00000, 0x05200000, 0x05200000)
  18. from space 1024K, 69% used [0x05200000, 0x052b1aa8, 0x05300000)
  19. to space 1024K, 0% used [0x05300000, 0x05300000, 0x05400000)
  20. tenured generation total 10240K, used 5853K [0x05400000, 0x05e00000, 0x05e00000)
  21. the space 10240K, 57% used [0x05400000, 0x059b75e8, 0x059b7600, 0x05e00000)
  22. Metaspace used 80K, capacity 2242K, committed 2368K, reserved 4480K
 519

啊!这个可能是世界上最丑的留言输入框功能~


当然,也是最丑的留言列表

有疑问发邮件到 : suibibk@qq.com 侵权立删
Copyright : 个人随笔   备案号 : 粤ICP备18099399号-2