Java Utililty Methods Memory Information

List of utility methods to do Memory Information

Description

The list of methods to do Memory Information are organized into topic(s).

Method

voidprintMemory()
print Memory
int mb = 1024 * 1024;
Runtime runtime = Runtime.getRuntime();
System.out.println("##### Heap utilization statistics [MB] #####");
System.out.println("Used Memory:" + (runtime.totalMemory() - runtime.freeMemory()) / mb);
System.out.println("Free Memory:" + runtime.freeMemory() / mb);
System.out.println("Total Memory:" + runtime.totalMemory() / mb);
System.out.println("Max Memory:" + runtime.maxMemory() / mb);
voidprintMemory(String label)
print Memory
System.out.println(label);
Runtime rt = Runtime.getRuntime();
System.out.println("  Total memory: " + rt.totalMemory());
System.out.println("  Free memory:  " + rt.freeMemory());
System.out.println("  Max memory:   " + rt.maxMemory());
voidprintMemory(String str)
print Memory
long total = Runtime.getRuntime().totalMemory();
long free = Runtime.getRuntime().freeMemory();
long used = total - free;
System.out.println("MEM  " + str + "    used: " + (used / 1024) + " KB    delta: "
        + ((used - lastMemUsed) / 1024) + " KB");
lastMemUsed = used;
voidprintMemoryInfo()
Print memory info
Runtime currRuntime = Runtime.getRuntime();
int nFreeMemory = (int) (currRuntime.freeMemory() / 1024 / 1024);
int nTotalMemory = (int) (currRuntime.totalMemory() / 1024 / 1024);
String message = nFreeMemory + "M/" + nTotalMemory + "M(free/total)";
System.out.println("memory:" + message);
voidprintMemoryInstruction(byte[] instruction)
print Memory Instruction
for (int i = 0; i < instruction.length; i++) {
    System.out.print(
            String.format("%8s", Integer.toBinaryString(instruction[i] & 0xff)).replace(' ', '0') + " ");
    if (i % 4 == 3)
        System.out.println();
voidshowMemory()
show Memory
System.out.println("free: " + Runtime.getRuntime().freeMemory() / 1000000.0 + " MB");
System.out.println("max: " + Runtime.getRuntime().maxMemory() / 1000000.0 + " MB");
System.out.println("total: " + Runtime.getRuntime().totalMemory() / 1000000.0 + " MB");
System.out.println();
voidshowMemoryInfo()
show Memory Info
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");
...