Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VS 2005 C# Smart Device Memory Leakage

9 views
Skip to first unread message

Seng Choe@discussions.microsoft.com Loke Seng Choe

unread,
Aug 12, 2008, 5:17:02 AM8/12/08
to
For example,
I have a DataGrid called dgEnqChassisNo.
I use the below code. If you run a few times, you notice that the object of
memory
being used is never release or dispose....so I am having memory leakage.
I am using Compact Framework 2 and visual 2005 to develop.
Anyone face this problem before??

SqlCeDataAdapter daPop = null;
SqlCeCommand sqlcmd = null;
SqlCeConnection sqlconn = null;
DataTable dtData = null;
try
{
MessageBox.Show("Run: " + GC.GetTotalMemory (true).ToString());
sqlconn = new SqlCeConnection("Data Source=\\VDTCS.sdf");
sqlconn.Open();

dtData = new DataTable();

daPop = new SqlCeDataAdapter("SELECT * FROM MSTSET", sqlconn);
daPop.Fill(dtData);

if (dgEnqChassisNo.DataSource != null)
{
DataTable dtRec = (DataTable)dgEngChassisNo.DataSource;
dtRec.Clear();
dtRec.Dispose();
dtRec = null;
dgEnqChassisNo.DataSource = null;
}
dgEnqChassisNo.DataSource = dtData;
}
catch (System.Exception ex)
{
MessageBox.Show("GetData: " + ex.Message);
}
finally
{
if (daPop != null)
{
daPop.Dispose();
daPop = null;
}

if (dtData != null)
{
dtData.Dispose();
dtData = null;
}

if (sqlconn != null)
{
sqlconn.Close();
sqlconn.Dispose();
sqlconn = null;
}

GC.WaitForPendingFinalizers();
GC.Collect();
MessageBox.Show("Finish: " + GC.GetTotalMemory
(true).ToString());

}

0 new messages