Fix unbounded StringBuilder retention in ThreadLocal (memory leak) by anuq · Pull Request #391 · elastic/ecs-logging-java

@anuq

getMessageStringBuilder() called setLength(0) which resets the logical length but never shrinks the internal char[] buffer. In thread-pool environments, a single large trace permanently bloats the buffer for that thread's lifetime, causing cumulative heap pressure.

Add a capacity threshold check (8 KB) that discards oversized buffers and replaces them with fresh instances, while still reusing normally-sized buffers for zero-allocation steady state.

Fixes elastic#381

SylvainJuge

@SylvainJuge SylvainJuge added bug

Something isn't working

and removed triage

Issues and PRs that need to be triaged

labels

Mar 31, 2026

jackshirazi