Skip to content

Instantly share code, notes, and snippets.

@hongster
Last active July 10, 2023 13:29
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hongster/b71d393b79cf111392eb to your computer and use it in GitHub Desktop.
Go runtime memory usage.
package main
import (
"fmt"
"runtime"
)
func main() {
// https://golang.org/pkg/runtime/#MemStats
var memStats runtime.MemStats
runtime.ReadMemStats(&memStats)
fmt.Printf("Memory in use: %d\n", memStats.Alloc)
fmt.Printf("Obtained from system: %d\n", memStats.Sys)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment