首页 > 解决方案 > freeMemory() 和 totalMemory() 的区别

问题描述

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();

标签: java

解决方案


freeMemory()for futuretotalMemory()for current and future

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


推荐阅读