Java Memory Free sampleFreeMemory()

Here you can find the source of sampleFreeMemory()

Description

Get current free memory
The current memory is saved for Memory usage analysis

License

Open Source License

Return

Free memory in MegaBytes

Declaration

public static double sampleFreeMemory() 

Method Source Code

//package com.java2s;

public class Main {
    static long startMemory;
    public final static int KILO = 1024;

    /**/*w w  w.j  a v a  2 s. c om*/
     * Get current free memory<br>
     * The current memory is saved for Memory usage analysis
     * @return Free memory in MegaBytes
     */
    public static double sampleFreeMemory() {
        startMemory = Runtime.getRuntime().freeMemory();
        return ConvertByteToMegaByte(startMemory);
    }

    public static double ConvertByteToMegaByte(long byteUnits) {
        return (double) byteUnits / (KILO * KILO);
    }
}

Related

  1. hasFreeMemory(float margin)
  2. isFreeMemoryAvailable()
  3. jvmFreeMemory(String size, Boolean txtByte)
  4. memoryFree()
  5. memoryFree()