I\'m trying to reduce the amount of garbage my web service generates, and I noticed that we\'re creating a new Json.NET JsonSerializer
instance for each request
If you don't use references, JsonSerializer
is thread-safe. There are however a few issues when using references in a multi-threaded context.
First, there is a bug in the default ReferenceResolver
that may cause duplicate reference id's to be used. See the GitHub issue here.
Secondly, when reusing a JsonSerializer
the default ReferenceResolver
is stateful so that if you use references your reference ids will continue to increment with each serialization call you make instead of starting at 1 for each. I created a GitHub issue to address this problem here.