Skip to content

Plagued with 'System.OutOfMemoryException' errors in .NET 7 Preview 4 #70718

Closed
@littlehoneybunnytuttifruttipumpkinpie

Description

I'm running a basic but memory & CPU intensive .NET 7 app with an API, on a Web Server 2016, but after it runs for a while, I'm running into continual 'System.OutOfMemoryException' errors in various parts of the program, especially as the memory usage grows, but not sure if this is related to max RAM usage as it's less than but almost 95% full (works fine with .NET 6 and same & higher RAM usage).
The issue happens with .NET 7 Preview 4, while same program works fine with .NET 6. I have not tested previous .NET 7 preview versions.
The errors seem to appear in several/different parts of the program, each performing variety of functions unrelated to each other.
The errors are also repeating (in similar parts of the program as previously) after restarting the program and after it runs for a while, filling up memory.
The program mainly loads data from Zip files, uncompresses it and stores it in static Dictionary to be served via API. It does the same operation in a loop, so no difference in behavior over time, just the memory errors happen after a while and after RAM usage is increasing).

Some of the errors are showing as follows:

[error: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.String.SplitWithoutPostProcessing(ReadOnlySpan`1 sepList, ReadOnlySpan`1 lengthList, Int32 defaultLength, Int32 count)
   at System.String.SplitInternal(ReadOnlySpan`1 separators, Int32 count, StringSplitMyData MyData)...
[error: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.String.Ctor(ReadOnlySpan`1 value)
   at System.Span`1.ToString()
   at System.Text.ValueStringBuilder.ToString()
   at System.Number.FormatDouble(Double value, String format, NumberFormatInfo info)
   ...
[error: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.IO.MemoryStream.set_Capacity(Int32 value)
   at System.IO.MemoryStream.EnsureCapacity(Int32 value)
   at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
   at Utils.Sys.CopyTo(Stream src, Stream dest) in ...

At least one example of the issue happens on the following line of code that operates on a Stream:
while ((cnt = src.Read(bytes, 0, bytes.Length)) != 0) dest.Write(bytes, 0, cnt);

Deployment machine:

  • .NET 7 Preview 4
  • Windows Server 2016
  • Intel Xeon E5-2697 (x2)

(unable to test on other hardware at this time due to large RAM usage that I don't have elsewhere)
Not sure how to help debug this issue, while for now I'm going back to .NET 6 just to be able to run the program properly.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions