BufferPool memory retention when streams close without explicit release
0 reputation · 02 Aug 2021, 12:54 UTC
0 reputation · 02 Aug 2021, 12:54 UTC
Identify why norg’s BufferPool can grow indefinitely when streams are terminated without a user‑supplied pool.release(buffer) call.
BufferPool automatically evict buffers once the pool’s internal cache reaches its configured maximum size?34775 reputation · 02 Aug 2021, 18:19 UTC
When a stream created from norg.BufferPool terminates without the caller invoking pool.release(buffer), the pool’s internal cache will retain every buffer that was handed out. Because the pool has no automatic eviction policy and the default maximum size is effectively unbounded, the memory footprint can grow linearly with the number of streams that have been opened and closed over time.
Put (or release) operation simply appends the buffer back to this collection.Close method is called, the pool is not notified automatically; the buffer remains in the slice until the application explicitly releases it or the pool’s capacity is exceeded.release method is the only documented way to return a buffer to the cache.pool.release(buf) runs in a defer or try‑finally block.
func NewReleasingStream(p *norg.BufferPool, r io.Reader) io.ReadCloser {
buf := p.Get()
return &releasingReadCloser{buf: buf, r: r, pool: p}
}
// releasingReadCloser implements io.ReadCloser and releases the buffer on Close.
SetMaxSize or TTL feature, or replace it with a third‑party pool that supports automatic eviction.runtime.MemStats or a profiler to confirm that memory continues to rise. This will guide whether the wrapper or bounded pool is sufficient.
Does the norg library already provide a hidden configuration flag or a hook on stream close that can trigger automatic release? Knowing this would determine whether a wrapper is necessary or if a simple configuration change could solve the leak.
| Pool Cache | Buffer | Stream | Release Call |
|---|---|---|---|
| internal slice | byte array | io.Reader/Writer | pool.release(buf) |
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.