I have memory problem in my application. Each time I fetch data from db and assign it to Grid, memory increases and sometimes when extensive searches are made the memory reaches to 1 G.B.
There can be other memory handling issues but to test that searching and binding data repeatedly consumes good amount of memory I have created a new winforms application and drop a button and a grid on it and write this code.
private void button1_Click(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(connString))
{
SqlDataAdapter adp = new SqlDataAdapter("select * from supplier", con);
DataSet ds = new DataSet();
con.Open();
adp.Fill(ds);
con.Close();
dataGridView1.DataSource = ds.Tables[0];
ds.Dispose();
}
}
Every time I click on this button, memory usage of this application increases, sometimes 3MB sometimes 4MB etc. There are around 2000 records in table and 12 columns of different types like datetime, VARCHAR(100), int etc.
Memory release after few minutes If I stop repeating search & bind activity.
Why memory just increases each time if amount of data is same?
I have also tried following code but no difference.
dataGridView1.DataSource = null;
dataGridView1.DataSource = ds.Tables[0];
I am using Telerik controls in my original application. Telerik grid consumes more memory than DataGridView, but DataGridView has same behavior.
Remember, this example is just consist of one form and a button and a grid on this form.
Thanks.