Skip to content

ReusableUtf8JsonWriter holds on the IBufferWriter<byte> after Return #62263

Open
@gfoidl

Description

@gfoidl

With Reset only the internal state is reset, but the output remains the same (cf. code).

So the IBufferWriter<byte> that is set in Rent will be referenced by the (pooled) Utf8JsonWriter, so the lifetime for the IBufferWriter<byte> is bound to the pooled Utf8JsonWriter -- at least until the next Rent when a new one is set. Thus the IBufferWriter<byte> can't be GCed.

In the STJ internal type Utf8JsonWriterCache an internal method is used to reset the output too.

I'm just curios if the extended lifetime is a latent problem or not.

Possible mitigations could be:

  • Dispose -- not really, as the instance can't be re-used then
  • Reset(Stream.Null) -- solves the lifetime problem, but allocates
  • reset by setting to a null-IBufferWriter (type needs to be created)
  • ?
  • make Utf8JsonWriter.ResetAllStateForCacheReuse public -- but this doesn't play nice with the disposal checks in that type

#9607 introduced the ReusableUtf8JsonWriter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-signalrIncludes: SignalR clients and servers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions