In addition to
OriginalGriff[
^]'s solution, i'd say that usage of
using statement - C# Reference | Microsoft Docs[
^] provides a way to quickly and easily dispose
IDisposable
objects without programmer's commitment.
So, if
DataTable[
^] or
DataAdapter[
^] causes memory leak, you can use them in between
using{}
statement, because both objects are disposable.
For example:
using (SqlCommand sqlCmd = new System.Data.SqlClient.SqlCommand(_getSPName, sqlCon) { CommandType = CommandType.StoredProcedure })
{
sqlCmd.CommandTimeout = 300;
using(SqlDataReader dr = sqlCmd.ExecuteReader())
using(DataTable dt = new DataTable())
dt.Load(dr);
}