Last active
August 29, 2015 14:24
-
-
Save bprashanth/503eb6f6dcbceb413aa5 to your computer and use it in GitHub Desktop.
timer leak
This file contains hidden or 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
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