转自:https://groups.google.com/forum/#!topic/golang-nuts/cCdm0Ixwi9A
资源泄露是指,未到指定的时间,内存资源不释放
package main
import (
"time"
"fmt"
"runtime"
)
func main() {
var ms runtime.MemStats
runtime.ReadMemStats(&ms)
fmt.Println("before, have", runtime.NumGoroutine(), "goroutines,", ms.Alloc, "bytes allocated")
for i := 0; i < 1000000; i++ {
time.After(time.Hour)
}
runtime.GC()
runtime.ReadMemStats(&ms)
fmt.Println("after, have", runtime.NumGoroutine(), "goroutines,", ms.Alloc, "bytes allocated")
time.Sleep(time.Minute) // uncomment this if you want to check memory usage externally, like with top
}