Re: How does "new" work in a loop?
- From: "John J. Hughes II" <no@xxxxxxxxxxx>
- Date: Mon, 10 Jul 2006 08:55:18 -0400
Jon,
Thanks for the debate, at this point I have not changed my mind but it does
give me food for thought. The next time I have some slow time I will
research the matter further taking you points and other points in this
thread into consideration.
But as a last comment: In one of you other messages in this thread you made
the following comment:
then the JIT wouldn't work out that first could never become true after
the first iteration and bigObject would therefore never be used after
that point. That's one of the few situations where it might make sense
to set a local variable to null.
Since I have some rather long running threads which create some long lived
variables it's possible that setting some of them to null cause memory to be
returned which was being held before.
Regards,
John
"Jon Skeet [C# MVP]" <skeet@xxxxxxxxx> wrote in message
news:MPG.1f18dfac673567f098d2dd@xxxxxxxxxxxxxxxxxxxxxxx
John J. Hughes II <no@xxxxxxxxxxx> wrote:
I do agree the memory is not marked... poor verbiage on my part.
I don't think your example really proves anything since you are calling
garbage collection.
Well, I can make an example which ends up garbage collecting due to
other activity if you want. It'll do the same thing. Just change the
call to GC.Collect() to
for (int i=0; i < 10000000; i++)
{
byte[] b = new byte[1000];
}
and you'll see the same thing.
I have no argument that when GC runs it will clean up
memory that is not being used. I personally believe that all references
to
a variable are not removed in a timely fashion unless you tell them too
be.
The key here is timely.
It's not a matter of the reference being removed. It's a case of the
release-mode garbage collector ignoring variables which are no longer
relevant.
Again as I have said I had a problem with memory creep, the only change I
did was add using statements the problem slowed down but was not
eliminated.
And *that* can have a significant impact - because many classes which
implement IDisposable also have finalizers which are suppressed when
you call Dispose. That really *does* affect when the memory can be
freed, and can make a big difference.
The second change was to add value=null statement (shotgun blast style)
and
the problem went away. Since it was a production system I used great
care
to change as little as possible so I really don't think I fixed any other
problems.
I'm afraid I still don't believe you saw what you claimed to be seeing
- not on a production system. You *would* see improvements in a
debugger, but that's a different matter.
If at some point in the near future if I can give you code which proves
my
point I will be happy too but the last time I had the problem it required
a
system running full blown for 14 days on average.
That being said I may have gotten my head wet and decided it was raining
when it was snowing. I decide to use an umbrella and my head it not wet
now.
I really suspect you were mistaken, I'm afraid.
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.
- References:
- How does "new" work in a loop?
- From: Tony Sinclair
- Re: How does "new" work in a loop?
- From: John J. Hughes II
- Re: How does "new" work in a loop?
- From: Jon Skeet [C# MVP]
- Re: How does "new" work in a loop?
- From: John J. Hughes II
- Re: How does "new" work in a loop?
- From: John J. Hughes II
- Re: How does "new" work in a loop?
- From: Jon Skeet [C# MVP]
- Re: How does "new" work in a loop?
- From: John J. Hughes II
- Re: How does "new" work in a loop?
- From: Jon Skeet [C# MVP]
- How does "new" work in a loop?
- Prev by Date: ToolStrip, visual inheritance
- Next by Date: Re: Regular Expression Help
- Previous by thread: Re: How does "new" work in a loop?
- Next by thread: Re: How does "new" work in a loop?
- Index(es):
Relevant Pages
|