When the buffer needs to grow (capacity < target), the current implementation discards existing data:
if cap(h.b) < h.allocFrameBuffer {
h.b = make([]byte, 0, h.allocFrameBuffer) // ❌ Existing data lost!
return
}
Any data in h.b is lost when the buffer is reallocated.
Also, the buffers never shrink. Once a decoder allocates a large buffer (e.g., 8MB for a large frame), it retains that memory permanently, even when subsequent frames are much smaller (e.g., 1MB).
Long-running services that process varying frame sizes will accumulate and hold onto peak memory usage indefinitely.