Class MemoryUtils

java.lang.Object
org.omegat.util.MemoryUtils

public final class MemoryUtils extends Object
Utils for calculate used memory. Calculation of object size is not perfect. It doesn't support multiple links to one object instance(object shares), memory alignments.
  • Method Details

    • getMemoryUsed

      public static long getMemoryUsed()
      Get memory which used by jvm.
      Returns:
      memory size
    • getMemoryFreeMB

      public static long getMemoryFreeMB()
      getMemory which is free by jvm.
      Returns:
      free memory size in MB.
    • getMemoryFree

      public static long getMemoryFree()
      getMemory which is free by jvm.
      Returns:
      free memory size
    • getMemoryAllocatedMB

      public static int getMemoryAllocatedMB()
      Get memory allocated by jvm.
      Returns:
      memory size in MB.
    • getMemoryAllocated

      public static long getMemoryAllocated()
      Get memory allocated by jvm.
      Returns:
      memory size
    • getMemoryLimitMB

      public static long getMemoryLimitMB()
      Get maximum memory which can be allocated by jvm.
      Returns:
      memory size in MB.
    • getMemoryLimit

      public static long getMemoryLimit()
      Get maximum memory which can be allocated by jvm.
      Returns:
      memory size
    • calcObjectSize

      public static long calcObjectSize(Object obj)
      Calculate memory usage for object.
      Parameters:
      obj - object
      Returns:
      memory size, or -1 if size is unknown