PC Review


Reply
Thread Tools Rate Thread

Beginner's question about GC

 
 
Ron M. Newman
Guest
Posts: n/a
 
      16th Jun 2006
Hi,

Let's say I have an object A.

Object A exclusively references object B.

Now: Object A goes out of scope.

does this mean the system garbage collects object A and B together?

I think it should. Am I correct?

Thanks
-Ron


 
Reply With Quote
 
 
 
 
Marina Levit [MVP]
Guest
Posts: n/a
 
      16th Jun 2006
I'm not sure what you mean by 'together'. But yes, both A and all of it's
B's (as long as nothing else is holding on to reference to the B's) would be
eligible for garbage collection. That doesnt' mean they will be garbage
collected immediately - just when the GC decides to run.

"Ron M. Newman" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> Let's say I have an object A.
>
> Object A exclusively references object B.
>
> Now: Object A goes out of scope.
>
> does this mean the system garbage collects object A and B together?
>
> I think it should. Am I correct?
>
> Thanks
> -Ron
>



 
Reply With Quote
 
=?ISO-8859-1?Q?G=F6ran_Andersson?=
Guest
Posts: n/a
 
      16th Jun 2006
There are other factors that might affect when the objects are
collected, like size and age of the objects. But, yes, the GC will
recognise both of the objects as up for collection at the same run
(unless they are in different generations, and the garbage collection
run only considers the first generation).

When the garbage collector runs it starts out by considering all objects
as collecteable, then looks through all references to exclude objects
that aren't collectable. It doesn't look for references in objects that
are collectable, so as A is collectable, the reference to B doesn't keep
B from being collectable.

Ron M. Newman wrote:
> Hi,
>
> Let's say I have an object A.
>
> Object A exclusively references object B.
>
> Now: Object A goes out of scope.
>
> does this mean the system garbage collects object A and B together?
>
> I think it should. Am I correct?
>
> Thanks
> -Ron
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: beginner asp.net question James Microsoft ASP .NET 1 14th Sep 2007 09:12 PM
Beginner Question, G Microsoft C# .NET 1 15th Mar 2007 05:51 PM
ASP.NET - Beginner question Marc Llenas Microsoft ASP .NET 1 16th Feb 2006 05:56 PM
No Class at ALL!!! beginner/beginner question =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?= Microsoft ASP .NET 7 3rd Feb 2005 02:47 PM
Re: C# Beginner question Christian Microsoft C# .NET 0 5th Sep 2003 10:07 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:07 AM.