Created
February 18, 2024 13:59
-
-
Save gkampitakis/b06d16297583c0441a3cdcfa49f9f710 to your computer and use it in GitHub Desktop.
Memory leaks in Go - Unbounded resource creation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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