mirror of
https://github.com/pion/webrtc.git
synced 2025-10-05 07:06:51 +08:00
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:

committed by
Sean DuBois

parent
cbbb1c29e5
commit
f29ef99b22
@@ -132,6 +132,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()
|
||||
for ; true; <-ticker.C {
|
||||
frame, _, ivfErr := ivf.ParseNextFrame()
|
||||
if errors.Is(ivfErr, io.EOF) {
|
||||
@@ -197,6 +198,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(oggPageDuration)
|
||||
defer ticker.Stop()
|
||||
for ; true; <-ticker.C {
|
||||
pageData, pageHeader, oggErr := ogg.ParseNextPage()
|
||||
if errors.Is(oggErr, io.EOF) {
|
||||
|
Reference in New Issue
Block a user