-
Notifications
You must be signed in to change notification settings - Fork 18k
runtime: leaking nested goroutines #16022
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
Comments
When you say that the program holds ~1.3GB of memory, how are you measuring that? Have you tried calling https://golang.org/pkg/runtime/debug/#FreeOSMemory ? |
I can reproduce this on Linux with GOMAXPROCS=1 on go1.6. What is happening is that you are spawning 600,000 goroutines. Depending on how the scheduler behaves, if all are spawned before any finish, you'll use up to ~1.3GB (~2K per goroutine). If goroutines finish faster than you spawn them, then memory usage will be quite low. That's why GOMAXPROCS matters, and why the GC at point A affects things. When you get to the sleep, Go is not using the ~1.3GB anymore. But it hasn't given that memory back to the OS yet. Wait 5 minutes or call debug.FreeOSMemory. |
I believe this is the expected behavior and that this issue should be closed. |
Thank you for your responses! I tried FreeOSMemory (btw small nit in the code I posted, I should wrap fmt.Println with a function), I waited 20 minutes, previously I also made system swapping. Nothing changed. I understand that Go likes to stash memory for later but how this pprof output can be explained, why it reports 168MB in runtime.malg 384B bucket (/debug/pprof/goroutine shows only 6 goroutines)? |
The allocations from malg (the goroutine allocator) are for goroutine descriptors. Goroutine descriptors are never freed, we keep a free list of them around. That is issue #9869. |
I'm going to close this as a dupe of #9869; that does sound like this problem. |
Hello,
go version
)?go version devel +09eedc3 Wed Jun 8 05:24:53 2016 +0000 darwin/amd64
tested also on 1.5 and 1.6 with the same results
https://play.golang.org/p/ATENOgjVp-
Program waits forever but is holding small amount of memory.
Program holds ~1.3GB of memory, after forcing GC in Point B nothing changes while GC in Point A makes program using only 22MB.
go tool pprof http://localhost:6060/debug/pprof/heap reports less memory usage but still indicates a leak, it is showing that nearly all memory is taken by descendants of runtime.newproc1.
I'm looking forward to answer any questions or hear why observed behaviour is expected :)
The text was updated successfully, but these errors were encountered: