RE: How the GC reclaim the memory of the objects with circled reference

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Chris Lyon [MSFT] (clyon_at_online.microsoft.com)
Date: 03/08/04


Date: Mon, 08 Mar 2004 18:09:14 GMT

Hi Bill

The .NET garbage collector uses a mark-sweep generational algorithm, which means it starts at GC Roots (locals, statics, threads, etc) and traces through their references.
Anything it doesn't touch is considered garbage and is eventually collected. Straight reference counting algorithms break down ith circular references, as you've
demonstrated.

You can read more about how .NET's GC works in these articles:
http://msdn.microsoft.com/msdnmag/issues/1100/gci/
http://msdn.microsoft.com/msdnmag/issues/1200/GCI2/default.aspx

And this site is great for general GC information, including descriptions of various algorithms and analysis:
http://www.memorymanagement.org

Hope that helps.
-Chris

--------------------
>From: foolmelon@hotmail.com (Bill)
>Newsgroups: microsoft.public.dotnet.languages.csharp,comp.lang.java.programmer
>Subject: How the GC reclaim the memory of the objects with circled reference
>Date: 7 Mar 2004 12:38:05 -0800
>Organization: http://groups.google.com
>Lines: 30
>Message-ID: <bcefb264.0403071238.53962a4a@posting.google.com>
>NNTP-Posting-Host: 67.69.243.132
>Content-Type: text/plain; charset=ISO-8859-1
>Content-Transfer-Encoding: 8bit
>X-Trace: posting.google.com 1078691885 32757 127.0.0.1 (7 Mar 2004 20:38:05 GMT)
>X-Complaints-To: groups-abuse@google.com
>NNTP-Posting-Date: Sun, 7 Mar 2004 20:38:05 +0000 (UTC)
>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-online.de!border2.nntp.ash.giganews.com!border1.nntp.ash.giganews.com!
nntp.giganews.com!news.glorb.com!postnews1.google.com!not-for-mail
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:227090
>X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
>
>Let's simplify using public data member. Say I have (the code should
>look same in C# and Java):
>
>Class A
>{
> public B m_b;
>}
>
>Class B
>{
> public A m_a;
>}
>
>A a = new A();
>B b = new B();
>a.m_b = b;
>b.m_a = a;
>
>When a and b are not referenced by any other objects, a and b still
>reference to each other. How does .NET know that a and b should be
>garbage collected?
>
>I raised the same question when JDK 1.0.x just came out, but don't
>recall that I saw a concreate answer (maybe I missed it somehow). I
>am pretty sure that Sun is handling it correctly in their current JVM.
> If anybody knows how it works in JVM, please make your comments here
>too. Thank you!
>
>Regards,
>Bill
>

-- 
This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at 
http://www.microsoft.com/info/cpyright.htm 
Note:  For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.  


Relevant Pages

  • Re: good algorithms come with practice and reading good code/books?
    ... I also suggest as a reference Herb Schildt's Complete Reference ... and algorithms was Mastering Algorithms with C ISBN ... also to suggest Algorithms in C parts 1-5, by Robert Sedgewick. ... suitable for quoting and easy searching with less is available, ...
    (comp.lang.c)
  • Re: Colored Noise in Noise cancellation
    ... I can't seem to find references on the performance of noise cancellation ... algorithms namely LMS, RLS, NLMS, etc when it comes to suppressing colored ... you point to a good reference? ... The fastest convergence ususally will ...
    (comp.dsp)
  • Re: about garbage collector
    ... There are plenty of algorithms for this. ... Some simple collectors copy all live objects thus found to a new area, ... map that tells them where there is free memory. ... updates it every time a reference becomes live or dies. ...
    (comp.lang.java.programmer)
  • Re: Attn: Gordon: Your "Electronics for Dummies"
    ... I wasn't writing about copyright the reference was ... Another example are algorithms. ... and experiences that are unique to me. ...
    (comp.robotics.misc)
  • Re: Jaccuse
    ... I can read a C program without reference to any ... I can use C to communicate programming ideas to other ... algorithms in the CACM should be written in Algol 60 there was no real ...
    (comp.lang.c)