I'm prepared to pay for help on this!!
My ASP.Net Core 3.1 application starts at around 450MB, and gradually runs up to around 4.5GB (and I suspect it would grow even more if more memory were available to it).
I have taken memory dumps at various stages, and analyzing them with dotMemory seems to show that JsonSerialiserOptions is a prime suspect:
Drilling to JsonSerializerOptions
shows the 3 instances. Two have negligible numbers, and if I further drill into the one of the 3 with the highest memory use, it's Key Retention Path shows this:
And this is where I need help. I really don't know what to make of these retention paths. I'm expecting that if the problem is in my code, I should find some class of my app at the bottom of a retention path? I need help trying to figure out from these retention paths where in my code the problem may be.
It turns out the problem was due to a bug in which a flexible, run-time-defined database query was retuning instances of type Object
, instead of instances of type dynamic
. The JsonSerializer correctly does NOT cache dynamic
types, but it DOES cache Object
types.
So each time the query ran, the JsonSerializer was caching the Object
structure. The fix was to ensure the the database query returned dynamic
types instead of Object
types.