static void compile()
{
CodeNamespace cn = new CodeNamespace("System.IO.TextReader");
CodeCompileUnit ccu = new CodeCompileUnit();
ccu.Namespaces.Add(cn);
CSharpCodeProvider icc = new CSharpCodeProvider();
CompilerParameters cplist = new CompilerParameters();
cplist.GenerateExecutable = false;
cplist.GenerateInMemory = false; //★ memory is high when true
cplist.ReferencedAssemblies.Add("System.dll");
cplist.ReferencedAssemblies.Add("System.XML.dll");
cplist.ReferencedAssemblies.Add("System.Web.Services.dll");
cplist.ReferencedAssemblies.Add("System.Data.dll");
CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu);
}
static void Main(string[] args)
{
Process proc = Process.GetCurrentProcess();
for (int i = 0; i < 300; i++)
{
compile();
}
long usedMemory = proc.PrivateMemorySize64;
Console.WriteLine(usedMemory); //print the memory size
}
当GenerateInMemory
设置为true
时,产品会分配更多内存吗?
结果是:
GenerateInMemory Memory Size (byte)
true 21688320
false 16424960
我的问题是: