Class MemoryUtils


  • public final class MemoryUtils
    extends java.lang.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 Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static long calcObjectSize​(java.lang.Object obj)
      Calculate memory usage for object.
      static long getMemoryAllocated()
      Get memory allocated by jvm.
      static long getMemoryLimit()
      Get maximum memory which can be allocated by jvm.
      static long getMemoryUsed()
      Get memory which used by jvm.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getMemoryUsed

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

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

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

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