Standard library / runtime/debug
debug.FreeOSMemory()
Forces GC and attempts to return unused memory to the operating system. No particular RSS reduction is guaranteed. Expected stdout: 'completed\n'.
Formal Syntax & Structure
go syntaxgo
func FreeOSMemory()Working Example
Example Snippetgo
package main
import ( "fmt" "runtime" "runtime/debug")
func main() { runtime.GC(); debug.FreeOSMemory(); fmt.Println("completed") }