Skip to content

JsonSerializer.SerializeToDocument results encapsulate buffers rented from the shared ArrayPool #73398

@eiriktsarpalis

Description

@eiriktsarpalis

Please do... and if I understood correctly that we're already dropping pool arrays as part of JsonDocument on success paths, please open an issue about that as well. Thanks.

Originally posted by @stephentoub in #73338 (comment)

Relevant code:

// For performance, share the same buffer across serialization and deserialization.
// The PooledByteBufferWriter is cleared and returned when JsonDocument.Dispose() is called.
PooledByteBufferWriter output = new(options.DefaultBufferSize);
using Utf8JsonWriter writer = new(output, options.GetWriterOptions());
WriteCore(writer, value, jsonTypeInfo);
return JsonDocument.ParseRented(output, options.GetDocumentOptions());

Likely introduced by #57327, so this is not a .NET 7 regression.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions