JsonSerializerOptions memory leak? #24230
-
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 8 replies
-
Do you see your applications memory grow unbounded? JsonSerializerOptions caches metadata about the types it serializes. It's usually bounded since the number of types in the application is bounded. That said, seeing it use 800 MB is surprising. Are you able to inspect what instances are being held by JsonSerializerOptions instance? /cc @steveharter \ @layomia |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Perhaps a solution is to have the |
Beta Was this translation helpful? Give feedback.
-
Thanks for the above pointers. |
Beta Was this translation helpful? Give feedback.
Thanks for the above pointers.
It turns out that in my building of the custom fields into the object being returned, it was actually returning an
object
and not adynamic
. This was causing the JsonSerializerOptions to cache each object result individually. I have now changed the code to ensure it returns adynamic
, and it seems this is (correctly) NOT being cached.The unbounded memory creep seems to have dissipated.