Java Utililty Methods Memory Used

List of utility methods to do Memory Used

Description

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

Method

longgetUsedMemory()
get Used Memory
gc();
long totalMemory = Runtime.getRuntime().totalMemory();
gc();
long freeMemory = Runtime.getRuntime().freeMemory();
long usedMemory = totalMemory - freeMemory;
return usedMemory;
doublegetUsedMemoryInMb()
get Used Memory In Mb
return getTotalMemoryInMb() - getFreeMemoryInMb();
intgetUsedMemoryInMegabytes()
get Used Memory In Megabytes
long usedMemory = Runtime.getRuntime().totalMemory();
int sizeInMegaBytes = (int) (usedMemory / BYTES_IN_1_MEGABYTE);
return sizeInMegaBytes;
doublegetUsedMemoryMBs()
get Used Memory M Bs
Runtime runtime = Runtime.getRuntime();
long memory = runtime.totalMemory() - runtime.freeMemory();
return memory / 1024.0 / 1024.0;
intgetUsedMemoryMegaBytes()
get Used Memory Mega Bytes
return (int) (getUsedMemoryBytes() / 1024 / 1024);
StringgetUsedMemoryStr()
get Used Memory Str
long totalMem = Runtime.getRuntime().totalMemory();
long freeMem = Runtime.getRuntime().freeMemory();
return bytesToString(totalMem - freeMem);
StringjvmInUseMemory(String size, Boolean txtByte)
Obtain JVM's In Use Memory.
return convertByteSize(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(), size,
        txtByte);
longmakeUsedPhysicalMemoryData(long systemPhysicalMaxValue, long systemPhysicalFreeValue)
make Used Physical Memory Data
long systemPhysicalUsedValue = systemPhysicalMaxValue - systemPhysicalFreeValue;
return systemPhysicalUsedValue;
longmeasureMemoryUse()
Measure memory used by the VM.
System.gc();
Thread.sleep(2000);
System.gc();
return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
longmemoryUsed()
memory Used
long mem = 0;
for (int i = 0; i < 10; i++)
    mem += memoryTotal() - memoryFree();
mem /= 10;
return mem;