Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSharpScript.EvaluateAsync() growing memory usage #31751

Open
stefanoIT opened this issue Dec 13, 2018 · 5 comments
Open

CSharpScript.EvaluateAsync() growing memory usage #31751

stefanoIT opened this issue Dec 13, 2018 · 5 comments

Comments

@stefanoIT
Copy link

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

@rummelsworth
Copy link

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

@MaxiPigna
Copy link

Any update to share on this issue?

@guylevy
Copy link

guylevy commented Oct 29, 2021

Any update on this issue which is open since almost 3 years?

@dpalat
Copy link

dpalat commented May 26, 2023

Any update on this issue which is open since almost 5 years?

@CyrusNajmabadi
Copy link
Member

The item is in the backlog. If you would like to contribute a fix, let us know. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants