我有使用一些数据表的简单函数,问题是在执行函数内存未释放后,使用探查器检查内存使用情况
private void button1_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(textBox1.Text.ToString()))
{
//Before 6,920K
this.Cursor = Cursors.WaitCursor;
Inventory _INV = new Inventory();
DataTable _dt1 = _INV.Check_Inventory_Item(textBox1.Text.ToUpper().ToString().Trim());
dataGridView1.DataSource = _dt1;
DataTable _dt2;
DataTable _dt3;
_INV.Check_Balances(textBox1.Text.ToUpper().ToString().Trim(), out _dt2, out _dt3);
dataGridView2.DataSource = _dt2;
dataGridView5.DataSource = _dt3;
dataGridView3.DataSource = null;
dataGridView4.DataSource = null;
_dt1.Dispose(); _dt1 = null;
_dt2.Dispose(); _dt2 = null;
_dt3.Dispose(); _dt3 = null;
GC.Collect();
//After 58,450K
this.Cursor = Cursors.Default;
}
}