I have a problem of "Memory Leak" in ASP.Net. I created a blank page made a connection with the database. The memory increases at a time when the page is accessed and not back to normal in no time! the highest peak memory was between 1GB !, then I have to recycle the "pool" in IIS ... I use the methods Connection.Close () and connection.Dispose (), but it seems that they do work. I searched the web more soulção could not find.
Is there any way to solve this problem without having to recycle the pool? Thanks for sharing knowledge !!!
This is the block in which the memory leak occurs:
SqlConnection cn = new SqlConnection("");
SqlCommand cm = new SqlCommand();
SqlDataReader dr = null;
try
{
cn.Open();
cm.Connection = cn;
cm.CommandTimeout = 600;
cm.CommandText = "";
cm.Parameters.Add("operation", SqlDbType.Int).Value = 1;
cm.Parameters.Add("now", SqlDbType.DateTime).Value = DateTime.Now;
dr = cm.ExecuteReader(CommandBehavior.SingleResult);
while (dr.Read())
{
//blah blah blah...
}
dr.Close();
}
catch (Exception ex)
{
}
finally
{
if (dr != null)
dr.Dispose();
cm.Dispose();
cn.Close();
cn.Dispose();
}