© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
25 replies
Ha4aJlbHuk_4a9l

❔ 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()
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
/bin/echo
500 times or that's some bug?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Memory leak : WeakReferences
C#CC# / help
17mo ago
Debugging memory leak
C#CC# / help
17mo ago
❔ dataset memory leak
C#CC# / help
3y ago
C#, Process Memory slowly going up but snapshots not indicating memory leak
C#CC# / help
2y ago