G
Guest
I am using SqlCommandBuilder to create an update command to update a table on
my DB of approx 20,000 rows and 10 columns. Unfortunately, I am detecting a
small memory leak using PerfMon to monitor Private Bytes and Working Set.
I am also using .NET Memory Profiler which is telling me that I have
thousands of Undisposed Instances under the NameSpace
System.Collections.Generic and the Name List<SqlParameter>.Enumerator.
There is one Undisposed Instance for each row in my DB on the first update
and approx 5,000-10,000 for each additional update. I am assuming these
undisposed items are my memory leak. Further I am assuming the undisposed
items are a list of Sql Parameters that sqlcommandbuilder is creating and not
disposing of when I dispose of the builder object.
Here is a code Snippet:
SqlCommand sqlSelect = new SqlCommand("select * from "+tableName,
this.getConnection());
SqlDataAdapter dsCmd = new SqlDataAdapter(sqlSelect);
DataTable dtable = dt; //declare a data table
openConnection();
//Sql Command Builder code
SqlCommandBuilder updateCmd = new SqlCommandBuilder(dsCmd);
dsCmd.UpdateCommand = updateCmd.GetUpdateCommand();
//Update DB with dataset
dsCmd.Update(dtable);
dtable.Dispose();
dsCmd.Dispose();
updateCmd.Dispose();
closeConnection();
Any thoughts on how I properly dispose of the apparent list of parameters
that SqlCommandBuilder is creating?
P.S. I have attempted to not use Command Builder and instead manually
declare my SQL Commands, but that took my update time to the DB from less
than a minute to almost 20 minutes. But that is for another thread.
my DB of approx 20,000 rows and 10 columns. Unfortunately, I am detecting a
small memory leak using PerfMon to monitor Private Bytes and Working Set.
I am also using .NET Memory Profiler which is telling me that I have
thousands of Undisposed Instances under the NameSpace
System.Collections.Generic and the Name List<SqlParameter>.Enumerator.
There is one Undisposed Instance for each row in my DB on the first update
and approx 5,000-10,000 for each additional update. I am assuming these
undisposed items are my memory leak. Further I am assuming the undisposed
items are a list of Sql Parameters that sqlcommandbuilder is creating and not
disposing of when I dispose of the builder object.
Here is a code Snippet:
SqlCommand sqlSelect = new SqlCommand("select * from "+tableName,
this.getConnection());
SqlDataAdapter dsCmd = new SqlDataAdapter(sqlSelect);
DataTable dtable = dt; //declare a data table
openConnection();
//Sql Command Builder code
SqlCommandBuilder updateCmd = new SqlCommandBuilder(dsCmd);
dsCmd.UpdateCommand = updateCmd.GetUpdateCommand();
//Update DB with dataset
dsCmd.Update(dtable);
dtable.Dispose();
dsCmd.Dispose();
updateCmd.Dispose();
closeConnection();
Any thoughts on how I properly dispose of the apparent list of parameters
that SqlCommandBuilder is creating?
P.S. I have attempted to not use Command Builder and instead manually
declare my SQL Commands, but that took my update time to the DB from less
than a minute to almost 20 minutes. But that is for another thread.