How can a memory leak occur in a garbage-collected language like Go?
Last updated
GC only frees unreachable memory, so leaks happen when objects stay reachable too long: ever-growing maps/caches, globals, or small slices pinning large backing arrays.
Goroutine leaks are common: a goroutine blocked forever on a channel or an uncancelled context keeps itself and its references alive. Unstopped
time.Tickers and unremoved callbacks leak too.Detect leaks by monitoring heap with
pprofand watching goroutine counts over time.