Java Memory Used getAvailableUnusedMemory()

Here you can find the source of getAvailableUnusedMemory()

Description

Find out how much unused memory (in bytes) is still available for the JVM to use.

License

BSD License

Declaration

public static long getAvailableUnusedMemory() 

Method Source Code

//package com.java2s;
// LICENSE:      This file is distributed under the BSD license.

public class Main {
    /**//from   ww w.j  ava 2  s . co  m
     * Find out how much unused memory (in bytes) is still available 
     * for the JVM to use.
     * On a MacBook Pro this call takes 0.5 usec.
     */
    public static long getAvailableUnusedMemory() {
        Runtime r = Runtime.getRuntime();
        return r.maxMemory() // how large the JVM heap can get
                - r.totalMemory() // current size of heap (<= r.maxMemory())
                + r.freeMemory(); // how much of currently allocated heap is unused
    }
}

Related

  1. calcUsedMemorySize()
  2. disposeUnusedMemory()
  3. getMemoryInUse()
  4. getMemoryUse()
  5. getMemoryUsed()
  6. getMemoryUsed()