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
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
Suggested improvement
or
Impact