Skip to content

bytes: bytes.Buffer uses an unbounded amount of memory even if its length stays bounded #5154

Closed
@gopherbot

Description

@gopherbot

by robryk:

If I read and write from/to a buffer in such a way that buffer's length remains bounded,
but it is never empty, the buffer's underlying byte slice will grow unboundedly.

What steps will reproduce the problem?
If possible, include a link to a program on play.golang.org.
http://play.golang.org/p/SsC896Kwd- runs out of memory, instead of running out of time.

What is the expected output?
I would expect the buffer to consume a bounded and small amount of memory, as it happens
when the buffer occasionally runs dry. 

I believe this problem is caused by the bytes.Buffer always allocating a larger buffer
in grow(n); even if the buffer's capacity is larger than twice the required size.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions