Q:

What is object graph in java?

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

A:

Objects have references to other objects which may in turn have references to more objects including the starting object. This creates a graph of objects, useful in reachability analysis. For instance, if the starting object is reachable (say it's in a thread's local stack) then all objects in the graph are reachable and an exact garbage collector cannot harvest any of these objects. Similarly, starting with a set of live objects (roots) if we create a list of all reachable objects, all other objects are garbage - fair game for collection.

A:

An 'Object Graph' is the conceptualization of all instances of the objects from your object model (the classes in your program) and their interconnections.
Take for example:
You have two classes
Class Foo
{
    String aString = "foo";
    Bar aBar;
}

Class Bar
{
    String aString = "boo";
}

If you were to create an instance, Foo myFoo and then create an instance of Bar myBar, and connect them, myFoo.aBar = myBar;, your object graph would consist of a single instance of Foo with a reference to a single instance of Bar. 
The garbage collector essentially uses the object graph to determine which instances in memory are still linked to something and possibly needed by the program, and which instances are no longer accessible and therefore can be deleted.

Someone on wikipedia puts it more eloquently than me:

Object-oriented applications contain
  complex webs of interrelated objects.
  Objects are linked to each other by
  one object either owning or containing
  another object or holding a reference
  to another object. This web of objects
  is called an object graph and it is
  the more abstract structure that can
  be used in discussing an application's
  state.

A:

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.

