zoukankan      html  css  js  c++  java
  • Java本机直接内存溢出

    JVM配置

    -XX:MaxDirectMemorySize=100M -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDetails

    测试代码

    package com.example.oom;
    
    import sun.misc.Unsafe;
    
    import java.lang.reflect.Field;
    
    public class DirectMemoryOOM {
        private static int _1MB=1024*1024;
    
        public static void main(String[] args) throws Exception {
            Field unsafeField= Unsafe.class.getDeclaredFields()[0];
            unsafeField.setAccessible(true);
            Unsafe unsafe=(Unsafe)unsafeField.get(null);
            while (true)
            {
                unsafe.allocateMemory(_1MB);
            }
        }
    }

    测试结果

    Exception in thread "main" java.lang.OutOfMemoryError
        at sun.misc.Unsafe.allocateMemory(Native Method)
        at com.example.oom.DirectMemoryOOM.main(DirectMemoryOOM.java:16)

    也没有dump,因为这个不是队内oom

  • 相关阅读:
    iOS开源控件库收集
    Ruby中的几种除法
    Font
    PlaySound
    STL
    APIs
    cin and cout
    CreateWindow
    Introducing Direct2D
    VC 常用代码
  • 原文地址:https://www.cnblogs.com/Brake/p/12892008.html
Copyright © 2011-2022 走看看