Java Memory Used getUsedMemory()

Here you can find the source of getUsedMemory()

Description

Returns a string which describes the amount of memory currently used by the JVM heap.

License

Open Source License

Return

a string which describes the amount of memory currently used by the JVM heap.

Declaration

public static String getUsedMemory() 

Method Source Code

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

public class Main {
    public static final long MEGA = 1048576;

    /**//from  ww  w.  jav  a  2  s.  c o  m
     * Returns a string which describes the amount of memory currently used by the JVM heap.
     * @return a string which describes the amount of memory currently used by the JVM heap.
     */
    public static String getUsedMemory() {
        final Runtime runtime = Runtime.getRuntime();
        return "Used memory: " + String.valueOf((runtime.totalMemory() - runtime.freeMemory()) / MEGA) + " MB";
    }
}

Related

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