473,387 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

dataGridView Memory Leak

..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
Feb 3 '06 #1
4 5556
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

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Peter" wrote:
..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

Feb 4 '06 #2
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

Feb 5 '06 #3
""Yuan Ren[MSFT]"" <v-****@microsoft.com> wrote in message
news:0Z**************@TK2MSFTNGXA02.phx.gbl...
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;
}
Feb 6 '06 #4
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

Feb 7 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: ranjeet.gupta | last post by:
Dear All Is the Root Cause of the Memory corruption is the Memory leak, ?? suppose If in the code there is Memory leak, Do this may lead to the Memory Corruption while executing the program ? ...
17
by: Josť Joye | last post by:
Hi, I have implemented a Service that is responsible for getting messages from a MS MQ located on a remote machine. I'm getting memory leak from time to time (???). In some situation, it is...
4
by: Don Nell | last post by:
Hello Why is there a memory leak when this code is executed. for(;;) { ManagementScope scope = new ManagementScope(); scope.Options.Username="username"; scope.Options.Password="password";...
20
by: jeevankodali | last post by:
Hi I have an .Net application which processes thousands of Xml nodes each day and for each node I am using around 30-40 Regex matches to see if they satisfy some conditions are not. These Regex...
23
by: James | last post by:
The following code will create memory leaks!!! using System; using System.Diagnostics; using System.Data; using System.Data.SqlClient; namespace MemoryLeak
8
by: Adrian | last post by:
Hi I have a JS program that runs localy (under IE6 only) on a PC but it has a memory leak (probably the known MS one!) What applications are there that I could use to look at the memory usage of...
7
by: Salvador | last post by:
Hi, I am using WMI to gather information about different computers (using win2K and win 2K3), checking common classes and also WMI load balance. My application runs every 1 minute and reports...
3
by: Jim Land | last post by:
Jack Slocum claims here http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript- memory-leaks/ that "almost every site you visit that uses JavaScript is leaking memory". ...
22
by: Peter | last post by:
I am using VS2008. I have a Windows Service application which creates Crystal Reports. This is a multi theaded application which can run several reports at one time. My problem - there is a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.