Class ObjectSizeCalculator


  • public class ObjectSizeCalculator
    extends Object
    • Constructor Detail

      • ObjectSizeCalculator

        public ObjectSizeCalculator​(MemoryLayoutSpec memoryLayoutSpec)
        Creates an object size calculator that can calculate object sizes for a given memoryLayoutSpecification.
        Parameters:
        memoryLayoutSpec - a description of the JVM memory layout.
    • Method Detail

      • calculateObjectSize

        public long calculateObjectSize​(Object obj)
        Given an object, returns the total allocated size, in bytes, of the object and all other objects reachable from it.
        Parameters:
        obj - the object; can be null. Passing in a Class object doesn't do anything special, it measures the size of all objects reachable through it (which will include its class loader, and by extension, all other Class objects loaded by the same loader, and all the parent class loaders). It doesn't provide the size of the static fields in the JVM class that the Class object represents.
        Returns:
        the total allocated size of the object and all other objects it retains.