RE: How the GC reclaim the memory of the objects with circled reference
From: Chris Lyon [MSFT] (clyon_at_online.microsoft.com)
Date: 03/08/04
- Next message: Nicholas Paldino [.NET/C# MVP]: "Re: Convert Date/Time to GMT"
- Previous message: Chris: "Re: XML/XSLT Transformations"
- In reply to: Bill: "How the GC reclaim the memory of the objects with circled reference"
- Next in thread: Bill: "Re: How the GC reclaim the memory of the objects with circled reference"
- Reply: Bill: "Re: How the GC reclaim the memory of the objects with circled reference"
- Messages sorted by: [ date ] [ thread ]
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.
- Next message: Nicholas Paldino [.NET/C# MVP]: "Re: Convert Date/Time to GMT"
- Previous message: Chris: "Re: XML/XSLT Transformations"
- In reply to: Bill: "How the GC reclaim the memory of the objects with circled reference"
- Next in thread: Bill: "Re: How the GC reclaim the memory of the objects with circled reference"
- Reply: Bill: "Re: How the GC reclaim the memory of the objects with circled reference"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|