Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
gopherbot opened this issue Mar 29, 2013 · 4 comments
Milestone

Comments

@gopherbot
Copy link

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.
@bradfitz
Copy link
Contributor

Comment 1:

Labels changed: added go1.1maybe, removed priority-triage.

Owner changed to @bradfitz.

Status changed to Accepted.

@bradfitz
Copy link
Contributor

Comment 3:

This issue was closed by revision 994f596.

Status changed to Fixed.

@bradfitz
Copy link
Contributor

Comment 4:

Thanks for the bug report and great repro!

@bradfitz
Copy link
Contributor

Comment 5:

This issue was updated by revision 43e38d5.

R=golang-dev, gri, robryk
CC=golang-dev
https://golang.org/cl/8173043

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1maybe label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants