Ha4aJlbHuk_4a9l
Ha4aJlbHuk_4a9l
CC#
Created by Ha4aJlbHuk_4a9l on 5/14/2023 in #help
❔ I somehow cause memory leak with Process.Start()
With this simple piece of code
using System.Diagnostics;

internal static class Program
{
static async Task Main(string[] args)
{
Console.WriteLine("Started");
ProcessStartInfo info = new ProcessStartInfo { FileName = "echo", Arguments = "hi" };
Console.ReadLine();
for (int i = 0; i < 300; i++)
{
Process proc = new Process { StartInfo = info };
proc.Start();
proc.WaitForExit();
proc.Dispose();
}
await Task.Delay(int.MaxValue);
}
}
using System.Diagnostics;

internal static class Program
{
static async Task Main(string[] args)
{
Console.WriteLine("Started");
ProcessStartInfo info = new ProcessStartInfo { FileName = "echo", Arguments = "hi" };
Console.ReadLine();
for (int i = 0; i < 300; i++)
{
Process proc = new Process { StartInfo = info };
proc.Start();
proc.WaitForExit();
proc.Dispose();
}
await Task.Delay(int.MaxValue);
}
}
when i publish and launch the program i can see in my system monitor (i'm on linux) that RAM usage just grows with each started process. E.g. with 100 starts that would grow from 30 to 43, with 300 it grows from 30mb to 54. I waited for some time but nothing was cleaned. GC.Collect() at the end of the program won't do anything, but(!) if i place it at the end of iteration the usage would grow 30 to 40 no matter how much times (i tried 100 and 500) i start the process which is how it should be. Am i doing something wrong here besides starting /bin/echo 500 times or that's some bug?
26 replies