Class ObjectGraphMeasurer


  • public final class ObjectGraphMeasurer
    extends Object
    A tool that can qualitatively measure the footprint (e.g., number of objects, references, primitives) of a graph structure.
    • Method Detail

      • measure

        public static ObjectGraphMeasurer.Footprint measure​(Object rootObject)
        Measures the footprint of the specified object graph. The object graph is defined by a root object and whatever object can be reached through that, excluding static fields, Class objects, and fields defined in enums (all these are considered shared values, which should not contribute to the cost of any single object graph).

        Equivalent to measure(rootObject, Predicates.alwaysTrue()).

        Parameters:
        rootObject - the root object of the object graph
        Returns:
        the footprint of the object graph
      • measure

        public static ObjectGraphMeasurer.Footprint measure​(Object rootObject,
                                                            com.google.common.base.Predicate<Object> objectAcceptor)
        Measures the footprint of the specified object graph. The object graph is defined by a root object and whatever object can be reached through that, excluding static fields, Class objects, and fields defined in enums (all these are considered shared values, which should not contribute to the cost of any single object graph), and any object for which the user-provided predicate returns false.
        Parameters:
        rootObject - the root object of the object graph
        objectAcceptor - a predicate that returns true for objects to be explored (and treated as part of the footprint), or false to forbid the traversal to traverse the given object
        Returns:
        the footprint of the object graph