-
July 7th, 2017, 02:18 AM
#1
using Form does not release memory
In Microsoft Visual Studio Enterprise 2015 I have created the simplest Windows Forms Application (.NET Framework 4.5.2.):
On the main Form1 there's a button1. When you press it the Form2 opens and closes immediately and loops with this Form2 open and closure.
On Windows 10 Task Manager you will see the memory usage increasing . I expect the memory to be released instead . Obviously after some time the memory usage will be huge and cause problems.
It's a test that anyone can do. How can this be possible? Even if I decrease the loop and wait for the cycle to finish, the memory is not released.
Code:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int loop = 100000;
for (int i = 0; i < loop; i++)
{
using (Form2 a = new Form2())
{
a.ShowDialog(this);
}
// Uncommenting the 2 following lines doesn't make any difference
// GC.Collect();
// GC.WaitForPendingFinalizers();
}
}
}
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
Close();
}
}
Mr. Burns
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|