Skip to content

JsonDocument lifecycle is not explicitly managed #1

@01Dri

Description

@01Dri

Gateway events are currently propagated internally as JsonDocument instances through a Channel.

Since JsonDocument implements IDisposable and relies on unmanaged buffers, the lack of an explicit disposal point can lead to memory leaks, especially under high event throughput.

Problem

  • JsonDocument flows across multiple layers
  • No clear ownership or disposal responsibility
  • Risk of continuous memory growth over time

Suggested improvement

  • Ensure Dispose() is called in the channel consumer
    or
  • Convert the payload into an intermediate model (e.g. GatewayPayload) and dispose the JsonDocument immediately after parsing

Impact

  • Better memory safety
  • Reduced coupling to System.Text.Json
  • Safer foundation for future gateway features

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions