Java Memory Usage memoryUsage()

Here you can find the source of memoryUsage()

Description

Calculates the memory usage according to Runtime.

License

Open Source License

Return

max, total, free and used memory (in bytes)

Declaration

public static String memoryUsage() 

Method Source Code

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

public class Main {
    /**//from  w  w w  . ja  v  a2s .co m
     * Calculates the memory usage according to Runtime.
     *
     * @return max, total, free and used memory (in bytes)
     */
    public static String memoryUsage() {
        final Runtime runtime = Runtime.getRuntime();

        runtime.gc();

        final long max = runtime.maxMemory();
        final long total = runtime.totalMemory();
        final long free = runtime.freeMemory();
        final long used = total - free;

        return String.format("%d\t%d\t%d\t%d", max, total, free, used);
    }
}

Related

  1. getMemUsage()
  2. getPercentMemoryUsage()
  3. getStringMemoryUsage(String s)
  4. getUsageMemory()
  5. memoryUsage()
  6. memoryUsage()
  7. printMemoryUsage()
  8. reportMemoryUsage()
  9. showMemoryUsage()