1 min read 39 words Updated Sep 24, 2026 Created Sep 24, 2026
#Go
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

	}

}