Re: How to destroy arrays
From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 06/01/04
- Next message: DraguVaso: "Re: "MDAC required" but it's installed..."
- Previous message: art: "Re: Access deployment with Visual Studio .Net 2003 Pro?"
- In reply to: Cor Ligthert: "Re: How to destroy arrays"
- Next in thread: Cor Ligthert: "Re: How to destroy arrays"
- Reply: Cor Ligthert: "Re: How to destroy arrays"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 1 Jun 2004 11:56:58 +0100
Cor Ligthert <notfirstname@planet.nl> wrote:
> > Just to clarify my meaning, I was asking when you believe the array
> > which the Foo variable's value was a reference to would be eligible for
> > garbage collection.
>
> I thought you did know that?
I know when it's eligible for garbage collection. What I was asking was
when *you* believed it would be eligible for garbage collection, and
what you'd have thought just from Scott's article.
> > Because when a is an integer, the garbage collector isn't interested in
> > whether or not the variable is reachable. When a is an array reference,
> > it is.
>
> Did you not know that as well?
Yes, I knew that before. It wasn't clear that you did, however.
> > So, in my example, because Foo is not used after
> > Console.WriteLine(Foo(0))
> > it isn't considered a "root" for garbage collection (in release mode -
> > in debug mode this optimisation isn't performed as the developer may
> > want to look at its value.
>
> Why should it not be, I thought I showed you that enough I hope I made it
> clear now for you?
Um, you haven't shed any light on garbage collection in this thread, as
far as I can see. What exactly do you think you've made clear, and
where?
> >> So why would that be different with = nothing.
>
> >Because when a is an integer, the garbage collector isn't interested in
> >whether or not the variable is reachable. When a is an array reference,
> >it is.
>
> Now I see you think that the = operater is for setting objects, no it is
> ment to set something, that can be 1 2 3 or nothing, depended on the kind of
> receiver it acts. And when a created object has no references anymore either
> way, do not make a mistake in that, (it can be also that it is referenced
> itself), than it is disposable (available) to the GC.
Not sure what you mean by "the kind of receiver it acts" but integers
themselves are never garbage collected. (Boxed versions are, of course,
but that's different.)
The = operator is for setting the value of a variable (or property),
either to a value type value or to a reference. Never to an actual
object. I think we agree on this, but I'm afraid I didn't understand
most of what you wrote above ("it can be also that it is referenced
itself" for instance)...
> > Actually, Scott didn't write that, fortunately - because it's not
> > true.Variables aren't "set to nothing automatically" - they're just not
> > considered to be roots by the garbage collector any more. What Scott
> > *did* imply (IMO) is that local variables were always considered to be
> > "roots" by the garbage collector until the end of the method. That's
> > not true.
>
> That was the reason of my first message to you, why are you additing to
> Scotts message. I nowhere readed that implyment of Scott it was only (YMO),
> however had told that, than I would not have connected a message.
Scott implied it when he specified the "rather than waiting for the end
of a procedure" in my opinion. If he'd said "rather than waiting for
the last use of the variable in the IL code" then I wouldn't have
written anything. He seemed to imply that there was something special
about the end of the procedure - otherwise why mention it?
-- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
- Next message: DraguVaso: "Re: "MDAC required" but it's installed..."
- Previous message: art: "Re: Access deployment with Visual Studio .Net 2003 Pro?"
- In reply to: Cor Ligthert: "Re: How to destroy arrays"
- Next in thread: Cor Ligthert: "Re: How to destroy arrays"
- Reply: Cor Ligthert: "Re: How to destroy arrays"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|