Use runtime.ReadMemStats to get current memory allocation stats like total allocs and GC counts.
Use runtime.ReadMemStats to populate a runtime.MemStats struct with current memory allocation statistics for your Go program.
import "runtime"
var m runtime.MemStats
runtime.ReadMemStats(&m)
fmt.Printf("Alloc: %v MB\n", m.Alloc/1024/1024)
This function updates the struct with metrics like total memory allocated, number of allocations, and garbage collection counts.
runtime.ReadMemStats gives you a snapshot of how much memory your Go program is using right now. It tells you how much space is currently in use and how many times your program has asked for new memory. Think of it like checking your bank account balance to see how much money you have spent and how many transactions you've made.