According to the API 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.Note that the amount of memory required to hold an object of any given type may be implementation-dependent. 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. Returns the amount of free memory in the Java Virtual Machine. Calling the gc method may result in increasing the value returned by freeMemory. In reference to your question, You may be wondering why there is a totalMemory() AND a maxMemory(). The answer is that the JVM allocates memory lazily. Lets say you start your Java process as such: Your process starts with 64mb of memory, and if and when it needs more (up to 1024m), it will allocate memory. Also, if you want to accurately calculate the amount of used memory, you do so with the following calculation : |