Class ReflectionSizeOf

java.lang.Object
org.ehcache.sizeof.SizeOf
org.ehcache.sizeof.impl.ReflectionSizeOf

public class ReflectionSizeOf extends SizeOf
SizeOf that uses reflection to measure on heap size of object graphs Inspired by Dr. Heinz Kabutz's Java Specialist Newsletter Issue #78
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
  • Constructor Details

    • ReflectionSizeOf

      public ReflectionSizeOf()
      Builds a new SizeOf that will not filter fields and will cache reflected fields
      See Also:
    • ReflectionSizeOf

      public ReflectionSizeOf(SizeOfFilter fieldFilter)
      Builds a new SizeOf that will filter fields and will cache reflected fields
      Parameters:
      fieldFilter - The filter to apply
      See Also:
    • ReflectionSizeOf

      public ReflectionSizeOf(SizeOfFilter fieldFilter, boolean caching, boolean bypassFlyweight)
      Builds a new SizeOf that will filter fields
      Parameters:
      fieldFilter - The filter to apply
      caching - Whether to cache reflected fields
      bypassFlyweight - whether "Flyweight Objects" are to be ignored
      See Also:
  • Method Details

    • sizeOf

      public long sizeOf(Object obj)
      Calculates the size in memory (heap) of the instance passed in, not navigating the down graph
      Specified by:
      sizeOf in class SizeOf
      Parameters:
      obj - the object to measure the size of
      Returns:
      the object size in memory in bytes
    • guessArraySize

      private long guessArraySize(Object obj)