A
Alexander Overmann
Hello,
currently we encounter several huge memoryproblems running .NET C#
Applications under Windows Terminal Servers/Citrix. Sometimes the program
claims 100 MB which is not very much at a single PC but a pain in the ass at
a Terminalserver when 20-25 Users start the program (25*100 = 2500 MB).
We made some analysis:
So we build a new project which only contains 2 forms. The first form just
has one button which starts the second form:
private void button1_Click(object sender, System.EventArgs e)
{
Form2 frm = new Form2();
frm.ShowDialog();
}
This second form contains a listview with 10 columns and a button in order
to fill it. After pressing the button the listview is filled:
private void button1_Click(object sender, System.EventArgs e)
{
Random rd = new Random();
Cursor.Current = Cursors.WaitCursor;
ListViewItem item;
string[] s = new string[10];
for (int i=0;i<100000;i++)
{
s[0] = rd.NextDouble().ToString();
s[1] = rd.NextDouble().ToString();
s[2] = rd.NextDouble().ToString();
s[3] = rd.NextDouble().ToString();
s[4] = rd.NextDouble().ToString();
s[5] = rd.NextDouble().ToString();
s[6] = rd.NextDouble().ToString();
s[7] = rd.NextDouble().ToString();
s[8] = rd.NextDouble().ToString();
s[9] = rd.NextDouble().ToString();
item = new ListViewItem(s);
this.lvData.Items.Add(item);
}
}
During this the memoryusage rises till 180 MB. If I close the second form
and return to the first one the memory decreases to 100 MB. This value didn't
decrease any more. So we change the code in the first form which opens the
second one:
private void button1_Click(object sender, System.EventArgs e)
{
Form2 frm = new Form2();
frm.ShowDialog();
frm.Dispose(); // NEW Statement
GC.Collect(); // NEW Statement
}
Now the memory changes after closing the second form from 100 MB to 25 MB.
This is much better but still not enough! Why does s single application with
one form and one button still uses 25 MB? At the beginning it just had 8 MB.
Run this program at a WTS by 20 Users and you have 500 MB wasted by a single
form with just one button!
We have also read the 1150 pages of ScaleNet.pdf from MSDN. I was wondering
about this sentence: AVOID CALLING GC.COLLECT. But this was the only way to
reduces the memory in my sampleapplication!
How can we solve this problem? Is there any better chance to get rid of this
waste of memory? At a normal PC it does not matter but it is critical at a
Terminal Server.
Thank you very much
currently we encounter several huge memoryproblems running .NET C#
Applications under Windows Terminal Servers/Citrix. Sometimes the program
claims 100 MB which is not very much at a single PC but a pain in the ass at
a Terminalserver when 20-25 Users start the program (25*100 = 2500 MB).
We made some analysis:
So we build a new project which only contains 2 forms. The first form just
has one button which starts the second form:
private void button1_Click(object sender, System.EventArgs e)
{
Form2 frm = new Form2();
frm.ShowDialog();
}
This second form contains a listview with 10 columns and a button in order
to fill it. After pressing the button the listview is filled:
private void button1_Click(object sender, System.EventArgs e)
{
Random rd = new Random();
Cursor.Current = Cursors.WaitCursor;
ListViewItem item;
string[] s = new string[10];
for (int i=0;i<100000;i++)
{
s[0] = rd.NextDouble().ToString();
s[1] = rd.NextDouble().ToString();
s[2] = rd.NextDouble().ToString();
s[3] = rd.NextDouble().ToString();
s[4] = rd.NextDouble().ToString();
s[5] = rd.NextDouble().ToString();
s[6] = rd.NextDouble().ToString();
s[7] = rd.NextDouble().ToString();
s[8] = rd.NextDouble().ToString();
s[9] = rd.NextDouble().ToString();
item = new ListViewItem(s);
this.lvData.Items.Add(item);
}
}
During this the memoryusage rises till 180 MB. If I close the second form
and return to the first one the memory decreases to 100 MB. This value didn't
decrease any more. So we change the code in the first form which opens the
second one:
private void button1_Click(object sender, System.EventArgs e)
{
Form2 frm = new Form2();
frm.ShowDialog();
frm.Dispose(); // NEW Statement
GC.Collect(); // NEW Statement
}
Now the memory changes after closing the second form from 100 MB to 25 MB.
This is much better but still not enough! Why does s single application with
one form and one button still uses 25 MB? At the beginning it just had 8 MB.
Run this program at a WTS by 20 Users and you have 500 MB wasted by a single
form with just one button!
We have also read the 1150 pages of ScaleNet.pdf from MSDN. I was wondering
about this sentence: AVOID CALLING GC.COLLECT. But this was the only way to
reduces the memory in my sampleapplication!
How can we solve this problem? Is there any better chance to get rid of this
waste of memory? At a normal PC it does not matter but it is critical at a
Terminal Server.
Thank you very much