What is object graph in java?

前端 未结 6 1080
轮回少年
轮回少年 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:13

    Object graph is a network of instances of classes of our application/software that currently exist in memory.

    Click to see image: http://blog.ploeh.dk/content/binary/Windows-Live-Writer/Compose-object-graphs-with-confidence_921A/Tree_1.png

    It can be a long chain of objects to a short one object graph also. E.g.: lets say we have classes like PetDog, Owner, PetKennel in a application. Now, PetDog has owner, Owner have one or many PetDog, PetDog is trained from a PetKennel and a PetKennel trains many PedDog. Now on implementation of those relationships in Object Oriented Approach we, a Owner (lets say you: a instance/object of Owner class) might reference (link to) many PetDog instances (if you have many dogs else you reference to only one PetDog), again a PetDog references to its particular owner instance/object (that is you in your's dogs case, Mr. John will be referenced by (linked to) his dog), you might have bought pet dog from different kennel club (where dogs are trained and sold also) then each of PetDog instances/objects references/linked to their particular Kennel clubs. This creates a complex network of objects related to each other.

    If you happen to represent each instances/objects (each objects of PetDog, Owner, PetKennel) as circle/square (or any shape) in your note/sketch book and draw arrow or lines to represent who object is linked (referencing) with which object then you create a object graph.

    Sometime it happens that when you delete or change links between those instances of any class then some instances might not be referenced (linked) to any other instances which will be removed by garbage collector.

提交回复
热议问题