Roslyn: CSharpScript.EvaluateAsync() growing memory usage

Created on 13 Dec 2018  路  2Comments  路  Source: dotnet/roslyn

Version 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:

image

image

The issue might be related to the following:

22219

10164

Area-Interactive Bug Interactive-ScriptingLogic

Most helpful comment

Any update to share on this issue?

All 2 comments

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:

  1. Create a new .NET Core 3.1 console app.

  2. Install the Microsoft.CodeAnalysis.CSharp.Scripting NuGet package.

  3. Replace the contents of Program.cs with this:

    using Microsoft.CodeAnalysis.CSharp.Scripting;
    using System;
    
    namespace ConsoleApp1
    {
       internal class Program
       {
           private static void Main(string[] args)
           {
               Once();
               Once();
           }
    
           private static void Once()
           {
               Console.WriteLine();
               GC.Collect();
               Console.WriteLine("before: " + GC.GetTotalMemory(true));
    
               const string EXPRESSION = "123";
               int result;
    
               using (var task = CSharpScript.EvaluateAsync<int>(EXPRESSION))
               {
                   result = task.Result;
               }
    
               Console.WriteLine("  " + result);
               GC.Collect();
               Console.WriteLine("after: " + GC.GetTotalMemory(true));
           }
       }
    }
    
  4. Set breakpoints at line 11 (after the first Once invocation) and 12 (after the second Once invocation).

  5. Run the app under Debug.

  6. When the first breakpoint hits, ensure the Diagnostic Tools window is open, and take a memory usage snapshot.

  7. 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:

image

Any update to share on this issue?

Was this page helpful?
0 / 5 - 0 ratings