dataGridView doesn't free Memory

V

Vincitori

Hallo,

I have a method which populates a dataGridView:

public void fillTest4DataGridView ()
{
this.dataGridView1.Rows.Clear ();
Random rand = new Random ();
for (int j = 0; j < 5; j++)
{
this.dataGridView1.Rows.Add (200);
for (int i = 0; i < 200; i++)
{
this.dataGridView1.Rows[i + (j * 200)].Cells[0].Value =
Resources.wait;
this.dataGridView1.Rows[i + (j * 200)].Height = 60;
this.dataGridView1.Rows[i + (j * 200)].Cells[1].Value =
(i + (j * 200)) + " hjgzttchjgvukjtg7zug";
this.dataGridView1.Rows[i + (j * 200)].Cells[2].Value =
"123153485489";
this.dataGridView1.Rows[i + (j * 200)].Cells[3].Value =
"ioziuhfvzuf67f ugui ";
this.dataGridView1.Rows[i + (j * 200)].Cells[4].Value =
"ih 89z8h 8u z76 hjg";
this.dataGridView1.Rows[i + (j * 200)].Cells[5].Value =
DateTime.Now.AddSeconds (rand.Next (10000));
this.dataGridView1.Rows[i + (j * 200)].Cells[6].Value =
rand.Next (1, 20000).ToString ("N0");
}
Application.DoEvents ();
}
}

Every time I call this method the memory the program uses increases by
50MB. I tried calling this.dataGridView1.Dispose(); to free the
memory, but that didn't help either.

Does anybody know what I can do to free the memory used?


Thank you,
- Vincent
 
G

Guest

To free the memory.. calling dispose method is'nt enough. Because it will not
clear memory untill the objects reference is not set to null, so first asign
null and then call dispose method.
 
N

Nicholas Paldino [.NET/C# MVP]

Vincitori,

How are you determining that the memory is not being freed? Are you
looking at the Task Manager? If so, then that is incorrect, as that shows
the current working set, not the memory consumed by the app. You need to
look at the .NET performance counters to see how much memory is actually
being used.
 
V

Vincitori

Hallo, Nicholas,

yes, I was looking at the TaskManager. Thanks, I didn't know that the
value displayed there was incorrect. I will take a look at the
performance counter.


Thank you,
- Vincitori
 
V

Vincitori

Hallo,

thank you. I also had a look at GC.Collect(); which reduced some
memory in the TaskManager, which, as I know now, isn't the correct place
to look for the memory consumed...


Thanks,
- Vincitori
----- Original Message -----
From: Vivek <[email protected]>
Sent: 12.11.2007 13:53:01 +0100
Subject: dataGridView doesn't free Memory

To free the memory.. calling dispose method is'nt enough. Because it will not
clear memory untill the objects reference is not set to null, so first asign
null and then call dispose method.

Vincitori said:
Hallo,

I have a method which populates a dataGridView:

public void fillTest4DataGridView ()
{
this.dataGridView1.Rows.Clear ();
Random rand = new Random ();
for (int j = 0; j < 5; j++)
{
this.dataGridView1.Rows.Add (200);
for (int i = 0; i < 200; i++)
{
this.dataGridView1.Rows[i + (j * 200)].Cells[0].Value =
Resources.wait;
this.dataGridView1.Rows[i + (j * 200)].Height = 60;
this.dataGridView1.Rows[i + (j * 200)].Cells[1].Value =
(i + (j * 200)) + " hjgzttchjgvukjtg7zug";
this.dataGridView1.Rows[i + (j * 200)].Cells[2].Value =
"123153485489";
this.dataGridView1.Rows[i + (j * 200)].Cells[3].Value =
"ioziuhfvzuf67f ugui ";
this.dataGridView1.Rows[i + (j * 200)].Cells[4].Value =
"ih 89z8h 8u z76 hjg";
this.dataGridView1.Rows[i + (j * 200)].Cells[5].Value =
DateTime.Now.AddSeconds (rand.Next (10000));
this.dataGridView1.Rows[i + (j * 200)].Cells[6].Value =
rand.Next (1, 20000).ToString ("N0");
}
Application.DoEvents ();
}
}

Every time I call this method the memory the program uses increases by
50MB. I tried calling this.dataGridView1.Dispose(); to free the
memory, but that didn't help either.

Does anybody know what I can do to free the memory used?


Thank you,
- Vincent
 
W

Willy Denoyette [MVP]

Vincitori said:
Hallo,

I have a method which populates a dataGridView:

public void fillTest4DataGridView ()
{
this.dataGridView1.Rows.Clear ();
Random rand = new Random ();
for (int j = 0; j < 5; j++)
{
this.dataGridView1.Rows.Add (200);
for (int i = 0; i < 200; i++)
{
this.dataGridView1.Rows[i + (j * 200)].Cells[0].Value =
Resources.wait;
this.dataGridView1.Rows[i + (j * 200)].Height = 60;
this.dataGridView1.Rows[i + (j * 200)].Cells[1].Value =
(i + (j * 200)) + " hjgzttchjgvukjtg7zug";
this.dataGridView1.Rows[i + (j * 200)].Cells[2].Value =
"123153485489";
this.dataGridView1.Rows[i + (j * 200)].Cells[3].Value =
"ioziuhfvzuf67f ugui ";
this.dataGridView1.Rows[i + (j * 200)].Cells[4].Value =
"ih 89z8h 8u z76 hjg";
this.dataGridView1.Rows[i + (j * 200)].Cells[5].Value =
DateTime.Now.AddSeconds (rand.Next (10000));
this.dataGridView1.Rows[i + (j * 200)].Cells[6].Value =
rand.Next (1, 20000).ToString ("N0");
}
Application.DoEvents ();
}
}

Every time I call this method the memory the program uses increases by
50MB. I tried calling this.dataGridView1.Dispose(); to free the
memory, but that didn't help either.

Does anybody know what I can do to free the memory used?


Thank you,
- Vincent


This function is not the reason for the increase memory consumption, what
you posted is not a complete sample, you must have some code running that
allocates memory, which is not getting released, such that it can be GC'd.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top