Skip to content

Process pipes aren't garbage collected #1166

@myrup

Description

@myrup

Process pipes aren't garbage collected

General

When using redirection for StandardOutput (and possibly StandardError, StandardInput as well) the pipes aren't garbage collected when the Process reference is collected.

The following silly piece of code lives (probably) forever in mono, but crashes in dotnet after 217 iterations on my machine:

public static void Main() {
            for (int i = 0; i < int.MaxValue; i++) {
                Process.Start(new ProcessStartInfo {
                    FileName = "ls",
                    UseShellExecute = false,
                    RedirectStandardOutput = true
                });
                Console.WriteLine(i);
            }
}

Adding a .StandardOutput.Close() extends lifetime 5 fold, indicating other things are not being collected.


Product Information:
 Version:            2.0.2
 Commit SHA-1 hash:  a04b4bf512

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.13
 OS Platform: Darwin
 RID:         osx.10.12-x64
 Base Path:   /usr/local/share/dotnet/sdk/2.0.2/

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.0
  Build    : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions