are there deadly embraces in garbage collection?

  • Thread starter Thread starter Jack Fox
  • Start date Start date
J

Jack Fox

I create a dictionary object "A" which contains many objects of class "B".
Each "B" also contains a reference (property) to its parent of class "A".

My question: when I either set "A" to a new occurence or set it to NULL, is
garbage collection going to take care of the former "A" and all of its "B"
objects, or do I need to do something with IDisposable? This is a rather
simple example, is it possible to construct more complicated scenarios of
cross-referencing that will inhibit garbage collection?
 
Jack Fox said:
I create a dictionary object "A" which contains many objects of class "B".
Each "B" also contains a reference (property) to its parent of class "A".

My question: when I either set "A" to a new occurence or set it to NULL, is
garbage collection going to take care of the former "A" and all of its "B"
objects, or do I need to do something with IDisposable? This is a rather
simple example, is it possible to construct more complicated scenarios of
cross-referencing that will inhibit garbage collection?
see
http://msdn.microsoft.com/msdnmag/issues/1100/GCI/default.aspx


The GC constructs a graph of all objects, where each object is a vertex, and
the refrences are the edges.

Then it analyzes this graph to find all objects which are unreachable from
any roots. Those objects will be collected. So your A and all it's B's
will be collected all together on the first collection in which no other
objects hold references to A or any B.

David
 
Back
Top