> Basically, think about what could get at the objects you've created. If
> nothing can get to them any more, they're eligible for garbage
> collection.
> > Basically, think about what could get at the objects you've created. If
> > nothing can get to them any more, they're eligible for garbage
[quoted text clipped - 3 lines]
> am trying to understand better, with respect to looking at my code, is how
> do I know if nothing can get to them anymore?
Well, something can only get at an object if you've told it where it
is. Very few classes will store static references to objects you tell
them about, and hopefully they should make it very clear when they're
going to do so! So, work out which objects you've told about which
objects (eg which lists you've added references to) and make sure that
either those objects are eligible for garbage collection at the same
time, or that you've removed the references to the objects which you
*want* to be eligible.
> Conversely, what I have to do
> now is look for the objects for which something can get to them. And I am
> still trying to get my arms around that. If I instantiate an object in a
> loop, how does this fit into that test?
That depends on what you do with the object. If you add it to a list
for example, then it'll live at least as long as the list does, unless
you later remove it. If you just use the value of some property of the
object which doesn't know its "parent", then the object will be
eligible for garbage collection when the loop goes into its next
iteration.
> One specific question I had about my service is this. Presumably anything
> that gets instantiated in a constructor is elgible for GC. Where is my
> constructor in a service. I go right into my elapsed_time event with my main
> loop which is creating objects, hydrating them, assigning values to string
> and integer variables which are defined within that timer's elapsed
> event.
I can't remember much about how the services infrastructure works
(every so often I work it out but then forget it again), but I assume
that either you've got some code which *does* call a constructor, you
the parameterless constructor for your service is called automatically
by the services infrastructure.
It's not that "anything that gets instantiated in a constructor is
eligible for GC" - it's "anything which is no longer referenced"
wherever it's been instantiated.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
hazz - 31 Jul 2005 20:46 GMT
Thank you so much for taking the time to explain it Jon. I know this is
basic stuff but it has been subtle. I am re-reading your explanation because
there are some key concepts I keep hearing, like objects whose references
have been removed.
Appreciatively,
-Greg
>> > Basically, think about what could get at the objects you've created. If
>> > nothing can get to them any more, they're eligible for garbage
[quoted text clipped - 45 lines]
> eligible for GC" - it's "anything which is no longer referenced"
> wherever it's been instantiated.