Skip to content

Instantly share code, notes, and snippets.

@gkampitakis
Created February 18, 2024 13:59
Show Gist options
  • Save gkampitakis/b06d16297583c0441a3cdcfa49f9f710 to your computer and use it in GitHub Desktop.
Save gkampitakis/b06d16297583c0441a3cdcfa49f9f710 to your computer and use it in GitHub Desktop.
Memory leaks in Go - Unbounded resource creation
var cache = map[int]int{}
func main() {
for i:=0; ; i++ {
// max items cache can hold is 1_000_000
if len(cache) >= 1_000_000 {
delete(cache, i-len(cache))
}
cache[i] = i
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment