dataGridView Memory Leak

P

Peter

..NET 2.0 Windows Forms app

It seems like there's a memory leak in the DataGridView

I have the following code:

this.dvOpenOrders.Table = dt.GetOpenOrders(whse_code,
this.dtpStartDate.Value, this.dtpEndDate.Value);
this.dataGridView1.DataSource = this.dvOpenOrders.Table;
long mem = GC.GetTotalMemory(false);

this code executes every 2 minutes and the mem variable keeps growing and
growing and so does the system Memory usage, eventually the system goes to a
crawl.
If I take out this line "this.dataGridView1.DataSource =
this.dvOpenOrders.Table;" the memory leak stops.

Does anyone have any ideas on how to solve this?

Thanks


Peter
 
G

Guest

Peter,
from the information you've provided it "sounds" like a connection isn't
being properly closed / disposed. Can you post more code? - particularly
the GetOpenOrders method.

GC.GetTotalMemory may not be a very reliable way to judge whether you have a
"memory leak", as there are just too many other variables in the picture.
Peter
 
Y

Yuan Ren[MSFT]

Hi Peter,

Thanks for posting!

As Peter mentioned (another Peter in the newsgroup:), the current problem
may be caused by the connection is not be released. So please attach more
codes about the GetOpenOrders here, it will help us to narrow down the
current issue.

In addition, the GC.GetTotalMemory just retrieves the number of bytes
currently thought to be allocated. And if the parameter is set to true, it
indicates this method can wait awhile for garbage collection before
returning.

However, I suggest you use the .NET Memory Profiler tool to monitor the
current application. You can get the tool from the link below:
http://www.scitech.se/memprofiler/

I appreciate your understanding!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support
 
P

Peter

"Yuan Ren[MSFT]" said:
Hi Peter,

Thanks for posting!

As Peter mentioned (another Peter in the newsgroup:), the current problem
may be caused by the connection is not be released. So please attach more
codes about the GetOpenOrders here, it will help us to narrow down the
current issue.

In addition, the GC.GetTotalMemory just retrieves the number of bytes
currently thought to be allocated. And if the parameter is set to true, it
indicates this method can wait awhile for garbage collection before
returning.

However, I suggest you use the .NET Memory Profiler tool to monitor the
current application. You can get the tool from the link below:
http://www.scitech.se/memprofiler/

I appreciate your understanding!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support


Here's the code for OpenOrders,

Here's the code:

///////////////////////////////////////////////////////////////////////////////////////////////////////////

this.dvOpenOrders.Table = dt.GetOpenOrders(sql);
try
{
this.dataGridView1.DataSource =
this.dvOpenOrders.Table; /
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public DataTable GetOpenOrders(sql)
{
DataSet ds = new DataSet();
DataTable dataTable = null;

try
{
if(this._oledbAdapter == null || this._dbConnection.State ==
System.Data.ConnectionState.Closed)
{
this._oledbAdapter = new IfxDataAdapter();
this._dbConnection = new IfxConnection(this._connectionString);
this._dbConnection.Open();
}

if(this._dbConnection.State == System.Data.ConnectionState.Open)
{
IfxTransaction myTrans =
this._dbConnection.BeginTransaction(IsolationLevel.ReadUncommitted);
myTrans.Commit();
this._oledbAdapter.SelectCommand = new IfxCommand(query,
this._dbConnection);
this._oledbAdapter.SelectCommand.CommandTimeout =
AppSettings.CommandTimeout;
this._oledbAdapter.Fill(ds, tableName);
this._oledbAdapter.Dispose();
}
}
catch(Exception e)
{
throw new Exception(query + ": " + Environment.NewLine +
Environment.NewLine, e);
}

if(ds.Tables.Count > 0)
dataTable = ds.Tables[0];

return dataTable;
}
 
Y

Yuan Ren[MSFT]

Hi Peter,

Thanks for your reply!

From the snippet of the code, there is not explicitly calling the close
method after executing the transaction. Based on my experience, this can
not cause the memory leak directly. As I mentioned in the previous thread,
the GC.GetTotalMemory method can not indicate whether there is memory leak
in the current application. So I wonder whether the size memory always
grows up till the application is crashed. If this is true, I want to know
how many memories the application use when the memory leak is encountered.

Regards,

Yuan Ren [MSFT]
Microsoft Online Support
 

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