获取堆大小 Vs 获取堆大小限制

Get heap size Vs Get heap size limit

我不明白 totalMemory() 和 maxMemory() 之间的区别。

通过调用获取 VM 堆大小:

Runtime.getRuntime().totalMemory();

通过调用获取 VM 堆大小限制:

Runtime.getRuntime().maxMemory();

根据 Android 文档:

Runtime.totalMemory():

Returns the total amount of memory in the Java virtual machine. The value returned by this method may vary over time, depending on the host environment.

Runtime.maxMemory():

Returns the maximum amount of memory that the Java virtual machine will attempt to use. If there is no inherent limit then the value Long.MAX_VALUE will be returned.