0

I'm writing a webservice that creates a file a user can download. The data source for that file is given by one or more URI's so I end up using Stream and Reader a lot. All of them are in using blocks. Even in the endpoint that offers the file I'm using return File(byte[], string, string) and the source stream of the byte[] is disposed.

Since I'm trying to type the data I receive via strings I'm using a lot of double.TryParse and Datetime.TryParse a lot.

I see some Garbage Collector runs but they are not freeing much. (Less than 1%)

But I'm observing a Heap size grow for every request I send with Swagger.

Some Numbers:

  • Memory usage before 1st request: 90 MB
  • Memory usage after 1st, 2nd, 3rd request: 180 MB, 277 MB, 480 MB
  • File size 200 Kb - the same for every request.

This led me to these questions:

  1. Where are files stored a web site hosted in IIS Express offers while debugging using Swagger? Memory or disc?

  2. Could there be a Swagger overhead that is the reason for this Memory growth?

  3. What else could be the source of this memory leak?

.Net 5.0

3rd party library in use: CsvHelper latest

Sputnick
  • 1
  • 2
  • 1
    Use a memory profiler to analyze the managed/unmanaged memory usage. Only that can reveal to you what happens under the hood. IIS Express/IIS can cache frequent used resources in memory, but those should be only seen in unmanaged memory and they are not memory leak. – Lex Li Oct 09 '21 at 01:01
  • I already did memory profiling. It shows me e.g. a lot of StringBuilders probably created by my TryParse calls. But it doesn't show me the source of that mem usage. Average 200 MB memory for a 200 Kb result is not accaptable. – Sputnick Oct 09 '21 at 08:28
  • "it doesn't show me the source of that mem usage" indicates you should spend more time on the vendor documentation (or if they have video tutorials on how to use the tool). The nature of .NET makes all profilers capable of showing where objects come from. – Lex Li Oct 09 '21 at 16:28

0 Answers0