freeMemory()和totalMemory()之间的区别

时间:2018-11-03 03:50:51

标签: java

freeMemory()totalMemory()有什么区别?两者都是JVM当前可用的内存总量。

    /**
     *
     * @return  an approximation to the total amount of memory currently
     *          available for future allocated objects, measured in bytes.
     */
    public native long freeMemory();

    /**
     *
     * @return  the total amount of memory currently available for current
     *          and future objects, measured in bytes.
     */
    public native long totalMemory();

1 个答案:

答案 0 :(得分:0)

freeMemory()for future,而totalMemory()for current and future

从字面上看,freeMemory()告诉新分配对象的内存,totalMemory()告诉总内存(已分配的内存+可用内存)