Skip to content

Instantly share code, notes, and snippets.

@gkampitakis
Created February 18, 2024 14:07
Show Gist options
  • Save gkampitakis/f2f8262f6e553ab4ef71e0e71bb109bd to your computer and use it in GitHub Desktop.
Save gkampitakis/f2f8262f6e553ab4ef71e0e71bb109bd to your computer and use it in GitHub Desktop.
Memory leaks in Go - Goroutines
func runJobs(cancel <-chan struct{}) {
for {
go func() {
// create a 1Gb slice
bigSlice := make([]byte, 1_000_000_000)
// do some work with the data
_ = bigSlice
// wait until a cancellation signal is received
<-cancel
}()
time.Sleep(10 * time.Second)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment