Avoid leaking tickers

In Go 1.22 and earlier, a ticker needs to be explicitly stopped
when it's no longer useful in order to avoid a resource leak.
In Go 1.23 and later, an orphaned ticker will eventually be
garbage collected, but it's still more thrifty to stop it early.
This commit is contained in:
Juliusz Chroboczek
2024-08-01 10:39:30 +02:00
committed by Sean DuBois
parent cbbb1c29e5
commit f29ef99b22
15 changed files with 34 additions and 9 deletions

View File

@@ -194,6 +194,7 @@ func main() {
// * avoids accumulating skew, just calling time.Sleep didn't compensate for the time spent parsing the data
// * works around latency issues with Sleep (see https://github.com/golang/go/issues/44343)
ticker := time.NewTicker(time.Millisecond * time.Duration((float32(header.TimebaseNumerator)/float32(header.TimebaseDenominator))*1000))
defer ticker.Stop()
frame := []byte{}
frameHeader := &ivfreader.IVFFrameHeader{}
currentTimestamp := uint64(0)