Skip to content

Instantly share code, notes, and snippets.

@bprashanth
Last active August 29, 2015 14:24
Show Gist options
  • Save bprashanth/503eb6f6dcbceb413aa5 to your computer and use it in GitHub Desktop.
Save bprashanth/503eb6f6dcbceb413aa5 to your computer and use it in GitHub Desktop.
timer leak
import (
"log"
"math"
"runtime"
"time"
)
func timeLeaker() {
tick := time.Tick(1)
<-tick
}
func timeTicker() {
tick := time.NewTicker(1)
defer tick.Stop()
<-tick.C
}
func main() {
memStats := &runtime.MemStats{}
runtime.ReadMemStats(memStats)
for i := 0; ; i++ {
//timeTicker()
timeLeaker()
if math.Mod(float64(i), 10.0) == 0.0 {
runtime.ReadMemStats(memStats)
log.Printf("i %d alloc %+v, objects %+v", i, memStats.HeapAlloc, memStats.HeapObjects)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment