import (
"fmt"
"runtime"
"time"
)
func toMb(b uint64) float64 {
return float64(b) / 1000 / 1000
}
func main() {
for {
time.Sleep(2 * time.Second)
var m runtime.MemStats
runtime.ReadMemStats(&m)
fmt.Println(toMb(m.Alloc)) // currently heap usage
}
}