Skip to content

Instantly share code, notes, and snippets.

@fxsjy
Created April 12, 2013 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fxsjy/5368803 to your computer and use it in GitHub Desktop.
Save fxsjy/5368803 to your computer and use it in GitHub Desktop.
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