You can get the system's free memory in Go using the os
package.
Here's an example code snippet:
main.go461 chars24 lines
In this code, we are using the runtime
package to read the memory statistics of the Go program. We then use the MemStats
struct to get the amount of allocated memory, the amount of heap memory still in use, the amount of memory (including virtual memory) obtained from the system and finally the amount of free memory in the system.
gistlibby LogSnag