Created
February 18, 2024 14:20
-
-
Save gkampitakis/7405b99701bacc6e02576ffdcf16a34f to your computer and use it in GitHub Desktop.
Memory leaks in Go - Not stopping time.Ticker
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
func main() { | |
for { | |
ticker := time.NewTicker(1 * time.Second) | |
// do something with the ticker | |
_ = <-ticker.C | |
// stop the ticker to release associated resources | |
ticker.Stop() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment