程序打印内存大小

/**
 * -XX:+UseTLAB 用本地缓存 -XX:-DoEscapeAnalysis 不使用逃逸分析 -XX:+PrintGCDetails
 * 打印GC的详细信息
 * 
 * @author chengluchao
 *
 */
public class 程序打印内存大小 {

    public static void main(String[] args) {
        byte[] b = new byte[10240000];
        printMemory();

    }

    static void printMemory() {
        System.out.println("total:" + Runtime.getRuntime().totalMemory());
        System.out.println("free:" + Runtime.getRuntime().freeMemory());
    }

}

有微量的误差,程序本身也要占用内存;

posted @ 2018-07-18 10:01  路迢迢  阅读(286)  评论(0编辑  收藏  举报