Skip to content

Process pipes aren't garbage collected #24476

@Petermarcu

Description

@Petermarcu

@myrup commented on Sat Dec 16 2017

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.

.NET Command Line Tools (2.0.2)

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

[EDIT] Add C# syntax highlighting by @karelz

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions