美文网首页
java.lang.OutOfMemoryError: GC o

java.lang.OutOfMemoryError: GC o

作者: 邵红晓 | 来源:发表于2020-05-18 15:07 被阅读0次

    oracle官网的解释:
    The concurrent collector will throw an OutOfMemoryError if too much time is being spent in garbage collection: if more than 98% of the total time is spent in garbage collection and less than 2% of the heap is recovered, an OutOfMemoryError will be thrown. This feature is designed to prevent applications from running for an extended period of time while making little or no progress because the heap is too small. If necessary, this feature can be disabled by adding the option-XX:-UseGCOverheadLimit to the command line.

    • JVM的一种推断,如果垃圾回收耗费了98%的时间,但是回收的内存还不到2%,就报这个错
      程序基本上耗尽了所有的可用内存, GC也清理不了,
     private static final int _1MB= 1024 * 1024;  //约1m
        public static void main(String[] args) {
            //总共约8m多,堆大小设置不超过8388608B即8.388608m就会内存溢出,但是需要整数,小于8M就会重现这个错误
            byte[] a1, a2, a3, a4;
            a1 = new byte[2 * _1MB];
            a2 = new byte[2 * _1MB];
            a3 = new byte[2 * _1MB];
            a4 = new byte[2 * _1MB];
        }
    java.lang.OutOfMemoryError: Java heap space
    Dumping heap to D:\gc.hprof ...
    Heap dump file created [8401640 bytes in 0.017 secs]
    Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
        at shengsiyuan.jdk8.jvmCon.GcOverhead.main(GcOverhead.java:14)
    
    • 打印出日志
      java -Xms10M -Xmx10M -Xmn2M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=D:\gc.hprof -XX:+PrintGCDetails -Xloggc:D:\gc.log TestMainClass
    • gc.hprof 查看 使用MAT查看

    Leak Suspects

    image.png

    问题解决

    • 代码问题有内存泄露

    相关文章

      网友评论

          本文标题:java.lang.OutOfMemoryError: GC o

          本文链接:https://www.haomeiwen.com/subject/cfvuohtx.html