Skip to content

[.NET 6] BufferFileStreamStrategy fills GC Finalizer Queue #78553

@sharpSteff

Description

@sharpSteff

Description

In .NET 6, BufferedFileStreamStrategy lacks GC.SuppressFinalize(this) call, which leads to memory and performance degradation under heavy usage of buffered file streams.

For .NET 7 this issue is already fixed with #64741 by adding the GC.SuppressFinalize(this) to BufferedFileStreamStrategy. However, we are stuck with .NET 6 and I want Information about if there is a workaround for .NET 6 or plans to fix this issue there.

Reproduction Steps

Create and close a lot of FileStream instances with DefaultBufferSize. In the reported scenario, the application has heavy usage of loading bitmaps as file streams using the default buffer size, and this exercises the BufferedFileStreamStrategy.

Expected behavior

Memory and performance degradation should not occur under heavy usage of buffered file streams (using DefaultBufferSize).

Actual behavior

Using dotMemory, high numbers of finalizer-queued BufferedFileStreamStrategy instances are observed. These high numbers trigger the GC more often than in .NET Core 3.1. This leads to overall performance degradation (in both memory and execution time).

Regression?

Yes, from .NET Core 3.1.

Known Workarounds

Using non-buffered file streams, but that would come with different penalties.

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions