Print Current Memory Usage
In this post we show how you can print the state of the current memory usage in Go. To do this, we’ve created a function PrintMemUsage() to help out, so you can call this when ever you need to know. All the info we need can be acquired through the runtime package, which allows us to read the state of the memory into the MemStats struct. It returns stats like how much memory the program is using, how much of it the OS has allocated to it and the number of garbage collections.