You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reported on golang-nuts:
FreeOSMemory does a GC and then frees all unused spans. But with concurrent GC, spans
are not updated during GC. So if you do:
1. use lots of memory
2. FreeOSMemory
3. sleep
The memory from 1 won't be released.
---------- Forwarded message ----------
Subject: [go-nuts] Why memory is not garbaged collected here?
Hello everyone,
I've been playing a bit with Go to check the garbage collector, and I found an
unexpected behaviour (unexpected for me). I don't know if it is a bug or something that
I don't really understand.
Everything has been tested on tip version.
Program is here: http://play.golang.org/p/QbfGh5xnhF
package main
import (
"time"
// "runtime/debug"
)
func main() {
f()
// debug.FreeOSMemory()
// debug.FreeOSMemory()
time.Sleep(10 * time.Hour)
}
func f() {
a := make([]int, 100000000)
for i := range a {
a[i] = i
}
}
The program allocates 763 MB of RAM (on 64-bits architecture) and then sleeps for 10
hours. I've been monitoring the memory used and the GC work by setting GODEBUG=gotrace=1
With the FreeOSMemory() lines commented, the memory is never GC'd nor released back to
the system. I've waited about 30 minutes.
With one single line of FreeOSMemory(), the memory is not freed immediately (as I
expected) but it seems that in the 2-3 next automatic GC runs it is finally found and
freed, and eventually, released back to the OS.
With two FreeOSMemory() lines, the memory is released immediately (I suppose that in the
second call).
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: