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

strings: strings.Builder case memory leak #34754

Closed
szyhf opened this issue Oct 8, 2019 · 7 comments
Closed

strings: strings.Builder case memory leak #34754

szyhf opened this issue Oct 8, 2019 · 7 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@szyhf
Copy link

szyhf commented Oct 8, 2019

What version of Go are you using (go version)?

go version go1.13.1 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

GO111MODULE=""
GOARCH="amd64"
GOBIN="/Users/foo/go/bin"
GOCACHE="/Users/foo/Library/Caches/go-build"
GOENV="/Users/foo/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/foo/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.13.1/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/xq/b3m9nkcx6jlgmnsvyz8w_05r0000gn/T/go-build019996190=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I made an issue #34463 but there some mistake, then I make a simple demo to record the HeapInuse and its increasing too.

DemoCodeOfGoPlay

What did you expect to see?

Memory keep stable.

What did you see instead?

Memory increasing slowly.

image

@smasher164 smasher164 added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 8, 2019
@egonelbre
Copy link
Contributor

Each iteration the pfx is getting bigger hence you are always allocating a slightly bigger string.

See the code here https://play.golang.org/p/rZrJrrrgL4F

@szyhf
Copy link
Author

szyhf commented Oct 8, 2019

Each iteration the pfx is getting bigger hence you are always allocating a slightly bigger string.

See the code here https://play.golang.org/p/rZrJrrrgL4F

Oh……you are right ! I made another mistake.

Can you help me to see why the memory is leak in #34463 and the core code is in https://play.golang.org/p/o0cEeZ7o7xl and https://play.golang.org/p/o0cEeZ7o7xl

I made a mistake in demo, is not the same as the running one, the leak really confused me.

Tanks a lot

@egonelbre
Copy link
Contributor

GitHub issues should be used for tracking bugs and proposals only. If you wish for help with debugging move the discussion to a more appropriate place.

@szyhf
Copy link
Author

szyhf commented Oct 8, 2019

@egonelbre
Oh no, I really think there is some leaking there, but I'm can not reproduce it in a simple code. My production environment is leaking every day.

I'll have another try latter.

@egonelbre
Copy link
Contributor

@szyhf indeed there could be a leak, but it could be in many places. It could be in the code you posted, it could be in any of the third-party libraries (bingo, ormer, database driver), some other code. Indeed it could be in Go runtime as well, but it is unlikely.

The goal is to isolate the leak - such that it clearly demonstrates where the leak is. Community sites are much better for this rather than Go language issues.

@szyhf
Copy link
Author

szyhf commented Oct 8, 2019

@egonelbre Thanks, I'll try to reproduce it in a clear way

@szyhf szyhf closed this as completed Oct 8, 2019
@szyhf
Copy link
Author

szyhf commented Oct 8, 2019

BTW, the reason why I think there is a leak of strings.Builder is due to the pprof of heap shows that the Builder.WriteString() hold a lots.

@golang golang locked and limited conversation to collaborators Oct 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants