CSharpScript.EvaluateAsync() growing memory usage
See original GitHub issueVersion Used: 2.10.0
Steps to Reproduce:
It’s quite easy to reproduce, just run in Loop the following code:
string formula = "Math.Round((double)(15/(double)10*100),2)"; object result = await CSharpScript.EvaluateAsync(formula, o_scriptoptions);
Expected Behavior: I was not expecting an ever-growing memory usage.
Actual Behavior:
The behaviour is well described by the following pictures from our memory profiler, showing live instances and bytes:


Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How to avoid memory leak using Roslyn CSharpCompilation
I am using Roslyn in my project to dynamically compile scripts. I noticed that the memory usage of my application was astronomically high(20- ......
Read more >[Solved]-How to use Roslyn C# scripting in batch processing ...
it reuse the script<object> - it's not consuming more memory on second call to runasync . but we can do better: static void...
Read more >Compiling expression trees with Roslyn… without memory leaks
The memory leak problem The problem is that this Roslyn magic comes with an unfortunate side effect. During compliation EvaluateAsync generates ...
Read more >Best way to evaluate expressions dynamically in .NET?
I'm stuck at the part where I need to evaluate the expression in (2). ... I actually implemented it with Roslyn, but the...
Read more >my c# application usage memory is keep increasing every ...
This is absolutely unreliable method of observing the memory usage. Just disregard it. Some thing that it's impossible to have a leak of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Any update to share on this issue?
This hit an app I’m working on pretty hard. We run long “analysis” operations and were trying to run hundreds at once when we ran into this. Our expressions are numeric-only and simple enough that we easily transitioned to Jace.NET to avoid this memory leak in Roslyn, but we’ve got another app in which expressions can have string parameters and operations, which will prevent usage of Jace.NET.
I was about to create a new issue for this, so I’ll add what I had already written:
Version Used: Microsoft.CodeAnalysis.CSharp.Scripting 3.4.0. Also tried 3.5.0-beta3-final.
Steps to Reproduce:
Create a new .NET Core 3.1 console app.
Install the Microsoft.CodeAnalysis.CSharp.Scripting NuGet package.
Replace the contents of Program.cs with this:
Set breakpoints at line 11 (after the first
Onceinvocation) and 12 (after the secondOnceinvocation).Run the app under Debug.
When the first breakpoint hits, ensure the Diagnostic Tools window is open, and take a memory usage snapshot.
Let it continue to the next breakpoint, and then take another memory snapshot.
Expected Behavior:
No increase in allocated objects/memory.
Actual Behavior:
Some increase in allocated objects/memory: