Quantcast
Channel: CS-Script Source
Viewing all articles
Browse latest Browse all 355

Commented Unassigned: Stressing ScriptLibrary to test leak leaves Visual Studio unresponsive [6]

$
0
0
Hi,

Doing a simple stress test to see if the ScriptLibrary release scripts suffer leakage due to repetitive compilation. Doing the test freezes up VS 2013 to the point where you have to kill it using Task Manager. Nothing in the IDE responds to anything after trying to set a breakpoint while the test is running for a while. It seems to get incrementally slower also as the loop runs longer.

```
[TestMethod]
public void TestMethod1()
{
var b = new StringBuilder();
b.AppendLine("using System;");
b.AppendLine("public class Script {");
b.AppendLine(" public int Sum(int a, int b) {");
b.AppendLine(" return a+b;");
b.AppendLine(" }");
b.AppendLine("}");

for (int n = 0; n < 1000000000; n++)
{
dynamic script = CSScript.Evaluator.LoadCode(b.ToString());

int result = script.Sum(10, 20);
}
GC.Collect();
GC.WaitForFullGCComplete(10000);
Console.WriteLine("Done");
}



```
Comments: &gt; _I am too well aware of the assembly leakage shortcomings in the framework._ Great. For some it is still a news. You will be even more surprised to learn that MS developers are also suffering from this problem. Long-long time ago I logged the assembly leakage as a defect on Connect. I actually got their attention and one of the CLR dev leads accepted/confirmed the report as a design limitation. He also confessed that this problem is causing the major headache for the ASP.NET team. But he said that the problem is to stay because... it is too difficult to fix! And eventually (in ~year) they closed the defect as ... "FIXED". &gt; _The question (to myself), is that if I were to cache the IScript and only recompile when necessary,_ Actually if you go with CodeDom hosting model then caching is already done by CS-Script runtime. If you are loafing the script files then caching is performed on the system wide scale. If you are loading the script code then it's per-process. Regardless how many times the following code is executed the compilation will happen only once and there ever will be only a single new assembly in the current AppDomain: ```C# var SayHello = CSScript.LoadMethod(@"public static void SayHello(string greeting) { Console.WriteLine(greeting); }") .GetStaticMethod(); SayHello("Hello World!"); ``` You will find plenty of the code samples in this folder: <cs-script>\Samples\Hosting\CodeDOM

Viewing all articles
Browse latest Browse all 355

Trending Articles