Skip to content

Instantly share code, notes, and snippets.

@fxsjy
Created Apr 12, 2013
Embed
What would you like to do?
Memory Leak of Golang
Hi all,
I am studying Go, and find that it is very interesting and "battery" included.
In this mail, I want to ask something about the garbage collection rules of Go.
For example, in the following program.
package main
import (
"math/rand"
"time"
"runtime"
)
func DoSomeThing(){
a := make([][]interface{},10000)
for i:=0;i<len(a);i++{
a[i] = make([]interface{},10000)
for j:=0;j<len(a[i]);j++{
a[i][j] = rand.Float64()
}
}
}
func main() {
DoSomeThing()
for {
println("idle")
runtime.GC()
time.Sleep(2*time.Second)
}
}
It will allocate 1.6 GB memory on my windows x64 machine with go1.1 beta2.
I am confused that why the memory allocated by DoSometThing() is not freed?
Thanks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment