Java Memory Available getAvailableMemorySize()

Here you can find the source of getAvailableMemorySize()

Description

Get available memory size

License

Open Source License

Return

long

Declaration

public static long getAvailableMemorySize() 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from   w  ww . ja  va 2 s .c om*/
     *
     * Get available memory size
     *
     * @return long
     */
    public static long getAvailableMemorySize() {
        long maxMemorySize = 512 * 1024 * 1024;
        if (Runtime.getRuntime().maxMemory() > maxMemorySize) {
            maxMemorySize = Runtime.getRuntime().maxMemory();
        }
        long freeMemorySize = Runtime.getRuntime().freeMemory();
        long totalMemorySize = Runtime.getRuntime().totalMemory();
        long usedMemorySize = totalMemorySize - freeMemorySize;
        return maxMemorySize - usedMemorySize;
    }
}

Related

  1. getAvailableMemory()
  2. getAvailableMemory()
  3. getAvailableMemory()
  4. getAvailableMemory()
  5. getAvailableMemoryFraction()