D
Doker
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];
}
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];
}