I have a function which get sqls from a .sql file(about 400k).Then execute them. But I don't know why the memory used has increased so much(250MB for first execute).I tried 'list = null' and 'list.clear()'.But the memory used cannot be reduced. And the memory used will increase about 100MB after I execute the function.This code is written by resigned personnel.
I want to know how to solve it or make memory won't increase after each execution.
Sorry for my poor English.memory used in visualstudio
Code here
public static void UpgradeDatabase(DbHelper db,string deployPath)
{
try
{
string sqlPath = Path.Combine(deployPath, "Source", "UpdateDataBase.sql");
if (!System.IO.File.Exists(sqlPath))
{
throw new Exception("");
}
List<string> sqlList = GetSqlList(sqlPath, db.Database); //memory used will increase after this
if (sqlList == null)
{
throw new Exception("");
}
db.ExecuteSqlList(sqlList);
sqlList = null;
}
catch (Exception ex)
{
//
}
}
another function
private static List<string> GetSqlList(string sqlPath, string database)
{
var sqllist = new List<string>();
try
{
var fileInfo = new FileInfo(sqlPath);
string commandText = "";
string varLine = "";
var reader = new StreamReader(sqlPath, Encoding.GetEncoding("gb2312"));
while (reader.Peek() > -1)
{
varLine = reader.ReadLine();
varLine = varLine.Replace("[kms]", "[" + database + "]");
if (varLine == "")
{
continue;
}
if (varLine.Trim() != "GO" && varLine.Trim() != "go")
{
commandText += varLine;
commandText += "\r\n";
}
else
{
sqllist.Add(commandText);
commandText = "";
}
}
reader.Close();
if (!string.IsNullOrEmpty(commandText))
{
sqllist.Add(commandText);
}
return sqllist;
}
catch (Exception ex)
{
return null;
}
}