Created
April 12, 2013 02:21
-
-
Save fxsjy/5368803 to your computer and use it in GitHub Desktop.
Memory Leak of Golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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