What is an object graph?

Tim Rohaly

When used in connection with serialization, an object graph is a tree structure rooted at the object you have written to the ObjectOutputStream. The branches and leaves of the tree are all the objects which are reachable by following references from the root object. This structure is maintained by the ObjectOutputStream in order to ensure that the complete reachable state of the given object is serialized and to handle cyclic dependencies. The graph is computed on-the-fly, during the serialization process.

A side-effect of maintaining this graph is that an object which has already been written to the stream will not be written again - it will be replaced by an object stream identifier, simply a number used to point at the previously object. To force a changed object to be written in its entirety, you need to reset() the stream, which clears the object graph. See http://www.jguru.com/jguru/faq/view.jsp?EID=25970 for more information.