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:
Where are files stored a web site hosted in IIS Express offers while debugging using Swagger? Memory or disc?
Could there be a Swagger overhead that is the reason for this Memory growth?
What else could be the source of this memory leak?
.Net 5.0
3rd party library in use: CsvHelper latest