What is object graph in java?

前端 未结 6 1083
轮回少年
轮回少年 2020-12-28 13:54

Whenever I study Garbage Collector I hear the term object Graph. What does it mean exactly?

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-28 14:11

    What we are talking about is the mathematical notion of a directed graph that consists of nodes and edges that connect the nodes. An object graph is some graph whose nodes are objects, and whose edges are relationship of interest between the objects.

    In the case of the Java garbage collector, the object graph of concern is the graph of reachable objects. In this graph, the nodes are Java objects, and the edges are the explicit or implied references that allow a running program to "reach" other objects from a given one. (For example of an implied reference, there is an implied reference from an object to it's Class object, and hence to the heap objects holding the classes statics and its code ... but I digress.)

    As @Chandra Patni explained, garbage collection works by traversing the reachability graph consisting of all objects that can be reached from one of a set of starting points; the "root set" in GC terminology. Any object that is not found in this graph traversal can no longer influence the computation, and is therefore eligible to be garbage collected.

提交回复
热议问题