Print Current Memory Usage
In this post we show how you can print memory usage in golang. We do this by outputting the current state of memory at any given time to show how much ram has been allocated and gc cycles made. We have 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 [docs] 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.