Java Memory Information showMemoryInfo()

Here you can find the source of showMemoryInfo()

Description

show Memory Info

License

Open Source License

Declaration

public static void showMemoryInfo() 

Method Source Code

//package com.java2s;

public class Main {
    public static void showMemoryInfo() {
        final Runtime runtime = Runtime.getRuntime();

        final long maxMemory = runtime.maxMemory();
        final long allocatedMemory = runtime.totalMemory();
        final long freeMemory = runtime.freeMemory();

        System.out.println("------------------------------------------------------");
        System.out.println("free memory: " + (freeMemory / 1024.0 / 1024.0) + " Mb");
        System.out.println("allocated memory: " + (allocatedMemory / 1024.0 / 1024.0) + " Mb");
        System.out.println("max memory: " + (maxMemory / 1024.0 / 1024.0) + " Mb");
        System.out.println(//from  w  ww .j a v a 2s.  co  m
                "total free memory: " + (freeMemory + (maxMemory - allocatedMemory)) / 1024.0 / 1024.0 + " Mb");
        System.out.println("------------------------------------------------------");
    }
}

Related

  1. printMemory(String label)
  2. printMemory(String str)
  3. printMemoryInfo()
  4. printMemoryInstruction(byte[] instruction)
  5. showMemory()