Go uses a concurrent, non-blocking garbage collector that automatically reclaims memory for objects no longer referenced, with optional manual optimization via the arena package for bulk allocations. The runtime tracks object lifetimes using write barriers and generational heuristics to minimize pause times, while GODEBUG settings allow fine-tuning of specific runtime behaviors like panicnil or http2client. For high-performance scenarios requiring immediate memory reclamation, you can use arena.NewArena() to allocate a group of objects and arena.Free() to release them all at once without waiting for garbage collection.
import "arena"
a := arena.NewArena()
defer a.Free()
// Allocate objects in the arena
obj := arena.New[*MyType](a)
slice := arena.MakeSlice[int](a, 10, 10)
// All memory is freed when a.Free() is called
The //go:debug directive in source files or godebug blocks in go.mod can override default runtime behaviors, such as restoring pre-Go 1.21 panic(nil) behavior with //go:debug panicnil=1.