473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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
Nov 15 '05 #1
1 998
Very simple - the GC marks EVERYTHING as collectable, then walks though all
the references in every stack frame marking all referenceable objects (and
their child objects) as non-collectable. Objects that reference each other,
but have no 'live' reference in the current or parent stack frames will
remain marked collectable.

Richard

--
C#, .NET and Complex Adaptive Systems:
http://blogs.geekdojo.net/Richard
"Bill" <fo*******@hotmail.com> wrote in message
news:bc**************************@posting.google.c om...
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

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Jimmy Cerra | last post by:
I am a little confused how the memory for objects is allocated in JavaScript. David Flanagan, in "JavaScript: The Definitive Guide," states that each property of a class takes up memory space when...
9
by: Mike P | last post by:
I know everything about reference counting and making sure you don't have large objects lying around. I have also profiled my app with multiple tools. I know about the fact GC collects memory but...
5
by: Yasaswi Pulavarti | last post by:
does a command like, db2 drop table tabschema.tabname when run from the Aix prompt reclaim the disk space? Are there any other options? How can we make sure the disk space is reclaimed? Thanks,...
2
by: Ashish | last post by:
hi All, I have heard from some sources that there is a known issue with asp.net, in that its not able to effectively reclaim session memory, when using the InProc mode, I know VLO bug, but we...
20
by: mariano.difelice | last post by:
Hi, I've a big memory problem with my application. First, an example: If I write: a = range(500*1024) I see that python process allocate approximately 80Mb of memory.
3
by: Jim Land | last post by:
Jack Slocum claims here http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript- memory-leaks/ that "almost every site you visit that uses JavaScript is leaking memory". ...
14
by: Joe | last post by:
I'm trying to track down where objects are referenced because I want to clean up the memory when I'm done with them. I thought I found all references but it doesn't seem that way because calling...
1
by: Joe Peterson | last post by:
I've been doing a lot of searching on the topic of one of Python's more disturbing issues (at least to me): the fact that if a __del__ finalizer is defined and a cyclic (circular) reference is...
3
by: crazy420fingers | last post by:
I'm running a python program that simulates a wireless network protocol for a certain number of "frames" (measure of time). I've observed the following: 1. The memory consumption of the program...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.