Java Memory Available getAvailableMemory()

Here you can find the source of getAvailableMemory()

Description

get Available Memory

License

Open Source License

Declaration

public static long getAvailableMemory() 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static long getAvailableMemory() {
        long freeMemory = Runtime.getRuntime().freeMemory();
        return getMaximumMemory() - freeMemory;
    }//from ww w  .  j  a v  a2 s . c  o  m

    public static long getMaximumMemory() {

        long maximumMemory = Runtime.getRuntime().maxMemory();
        long totalMemory = Runtime.getRuntime().totalMemory();

        if ((maximumMemory <= 0) || (maximumMemory == Long.MAX_VALUE)) {
            // if maximum memory can not be determined or isn't defined, then default to the totalMemory
            maximumMemory = totalMemory;
        }
        return maximumMemory;
    }
}

Related

  1. availableMemory()
  2. availableMemoryPercent()
  3. getAvailableMemory()
  4. getAvailableMemory()
  5. getAvailableMemory()
  6. getAvailableMemoryFraction()
  7. getAvailableMemorySize()