c# compiler mem"leakage"
- From: Doker <doker0@xxxxx>
- Date: Wed, 05 Sep 2007 01:34:51 +0200
Lets consider following code:
while (true)
{
string[] t = new String[1024 * 1024 * 20];
}
You probably thing this is the good solution because "narrow scope of variable to the minimum". But wait. Mem usage is at level of 300MiB!
Now. Lets see what happens if we use:
string[] t;
while (true)
{
t = null;
t = new String[1024 * 1024 * 20];
}
Wow! Now mem is something at 30MiB. Who could know that?
So this is either compiler bug or framework's thing.
By the way: Add GC.Collect() for your VS not to hang up for a moment when you stop or pause. Do it like that:
string[] t;
while (true)
{
t = null;
GC.Collect();
t = new String[1024 * 1024 * 20];
}
.
- Follow-Ups:
- Re: c# compiler mem"leakage"
- From: Jon Skeet [C# MVP]
- Re: c# compiler mem"leakage"
- Prev by Date: Re: vs 2005 gui ide
- Next by Date: Re: c# compiler mem"leakage"
- Previous by thread: Re: vs 2005 gui ide
- Next by thread: Re: c# compiler mem"leakage"
- Index(es):
Relevant Pages
|
Loading