Java Memory Used stringMemoryUsedInMB()

Here you can find the source of stringMemoryUsedInMB()

Description

Returns the amount of memory currently used by the JVM, in megabytes, as a string.

License

BSD License

Declaration

public static String stringMemoryUsedInMB() 

Method Source Code

//package com.java2s;
// Licensed under the terms of the New BSD License. Please see associated LICENSE file for terms.

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

    /**//from  ww w . j a va  2  s.co m
     * Returns the amount of memory currently used by the JVM, in megabytes, as a string.
     */
    public static String stringMemoryUsedInMB() {
        String ret = String.format("%,d MB", memoryUsedInMB());
        return ret;
    }

    /**
     * Returns the amount of memory currently used by the JVM, in megabytes.
     */
    public static long memoryUsedInMB() {
        return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / MEGA;
    }
}

Related

  1. measureMemoryUse()
  2. memoryUsed()
  3. memoryUsed()
  4. memoryUsed()
  5. memoryUsedInMB()
  6. usedMemory()
  7. usedMemory()
  8. usedMemory()
  9. usedMemory()