Java Memory Used getUsedMemory()

Here you can find the source of getUsedMemory()

Description

Returns the current amount of memory (in MB) this JVM is using.

License

Open Source License

Return

used memory

Declaration

public static int getUsedMemory() 

Method Source Code

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

public class Main {
    /**/*  ww w  .  j  a  v  a 2s.  c o  m*/
     * Returns the current amount of memory (in MB) this JVM is using.
     *
     * @return used memory
     */
    public static int getUsedMemory() {
        return getAllocatedMemory() - getFreeMemory();
    }

    /**
     * Returns the allocated amount of memory (in MB) this JVM is using.
     *
     * @return allocated memory
     */
    public static int getAllocatedMemory() {
        return Math.round((float) (Runtime.getRuntime().totalMemory() / 1048576L));
    }

    /**
     * Returns the free amount of memory (in MB) belonging to JVM.
     *
     * @return free memory
     */
    public static int getFreeMemory() {
        return Math.round((float) (Runtime.getRuntime().freeMemory() / 1048576L));
    }
}

Related

  1. getMemoryUsed()
  2. getMemoryUsed()
  3. getMemoryUsed()
  4. getMemoryUsedBytes ()
  5. getMemoryUsege()
  6. getUsedMemory()
  7. getUsedMemory()
  8. getUsedMemory()
  9. getUsedMemory()