SQL update scripts taking too much memory and doesn't free it up I have this piece of code that executes update scripts on the database. I have 20 .sql files that contains about 400 update scripts. The overall size of the files is around 60MB. When I execute all the update scripts, it eats up about 400 MB of RAM and doesn't free it. I'm looking for ways to optimize this code.

private void ExeCuteCommand(SqlConnection conn, string script, bool flag)
    {
        SqlCommand command = new SqlCommand();
        command.Connection = conn;
        command.CommandType = CommandType.Text;
        command.CommandText = script;

        if (flag)
            command.ExecuteNonQuery();               
    }


EDIT: 

This is the calling method, basicall what it does is loop through the files, get the contents and pass the contents to the ExecuteCommand method.

private void ExecuteUpdateScripts(SqlConnection conn)
    {
        int step = 1;
        foreach (string update in Directory.GetFiles(scriptDirectory, @"SCRIPT UPDATE ??.sql"))
        {
            string updateScript = File.ReadAllText(updateSQL);
            ExeCuteCommand(conn, updateScript, true);

            step++;
        }
    }


I have looked at the Visual Studio profiler and this is the line the consumes a lot of memory command.ExecuteNonQuery();
As it seems you execute the SqlCommand only if flag == true so the first thing you should do is place a guard clause at the top of the method.  
The SqlCommand object implements the IDisposable interface, therefor you should enclose it in an using statement which takes care of the disposing of this object.  
the default value of the CommandType property is CommandType.Text so there is no need to assign it.  
there is a overloaded constructor, which takes the connection and the querystring so you should use it.  
Execute is not a compound word, so you shouldn't use PascalCase for this word. The method should be named ExecuteCommand().  
a variable named flag does not describe what its purpose is. Much better would be shouldBeExecuted.
you should always use braces {} although they are optional for single line if statements. Omiting them will lead to potential error prone code.  


Applying these points will lead to  

private void ExecuteCommand(SqlConnection conn, string script, bool shouldBeExecuted)
{
    if (!shouldBeExecuted) { return; }

    using (SqlCommand command = new SqlCommand(script, conn))
    {
        command.ExecuteNonQuery();               
    }
}