Created
May 2, 2016 01:34
-
-
Save vcabbage/55dfc2700dfd658d89204d775656a3e2 to your computer and use it in GitHub Desktop.
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
135 - heap objects before creating timers | |
22570169 - heap objects after creating timers | |
8031998 - heap objects after running GC, before timers expire | |
163 - heap objects after timers expire |
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
package main | |
import ( | |
"fmt" | |
"runtime" | |
"time" | |
) | |
func main() { | |
var m runtime.MemStats | |
runtime.ReadMemStats(&m) | |
fmt.Printf("%d - heap objects before creating timers\n", m.HeapObjects) | |
createTimers() | |
// See how many objects have been created | |
runtime.ReadMemStats(&m) | |
fmt.Printf("%d - heap objects after creating timers\n", m.HeapObjects) | |
// Run GC before timers have expired | |
runtime.GC() | |
runtime.ReadMemStats(&m) | |
fmt.Printf("%d - heap objects after running GC, before timers expire\n", m.HeapObjects) | |
// Wait for timers to expire | |
time.Sleep(time.Second * 3) | |
runtime.GC() | |
runtime.ReadMemStats(&m) | |
fmt.Printf("%d - heap objects after timers expire\n", m.HeapObjects) | |
} | |
func createTimers() { | |
for i := 0; i < 10000000; i++ { | |
time.NewTimer(time.Second * 2) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment