Java Memory Usage getMemoryUsage()

Here you can find the source of getMemoryUsage()

Description

Return the Difference (in MegaBytes) between the first sampled free memory and current free memory

License

Open Source License

Return

A positive number if there is less memory and a negative number if there is more

Declaration

public static double getMemoryUsage() 

Method Source Code

//package com.java2s;

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

    /**//from w  w w  . ja v a 2s  . co  m
     * Return the Difference (in MegaBytes) between the first sampled free memory and current
     * free memory
     * @return   A positive number if there is less memory and a negative number if there is more
     */
    public static double getMemoryUsage() {
        long diff = startMemory - Runtime.getRuntime().freeMemory();
        return ConvertByteToMegaByte(diff);
    }

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

Related

  1. getMemoryInfo()
  2. getMemoryInfo()
  3. getMemorySize(long size)
  4. getMemoryStatus()
  5. getMemoryUsage()
  6. getMemoryUsage()
  7. getMemoryUsage()
  8. getMemoryUsage()
  9. getMemoryUsage()