You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It sleeps at the end so you can run top or equivalent and see that it will be using 100% of a CPU core keeping the Tickers up to date even though the user no longer has access to them.
This is unfortunate but it was decided in #8001 that it was too difficicult to Stop the Tickers when they are garbage collected.
The documentation for NewTicker got changed after this, but not the documentation for Tick.
It currently reads
Tick is a convenience wrapper for NewTicker providing access to the ticking channel only. Useful for clients that have no need to shut down the ticker.
It doesn't say why you might want to shut the Ticker down.
My suggestion for a re-word is this
Tick is a convenience wrapper for NewTicker providing access to the ticking channel only. Note that this leaks associated resources; use NewTicker and Stop to avoid that.
That is possibly too alarmist, but I wanted the docs to note clearly that using time.Tick is leaking something which can't be recovered.
The text was updated successfully, but these errors were encountered:
Calling
time.Tick
causes aTicker
to leak because there is no interface toStop()
it.Here is a demonstration which starts 100,000 go routines each of which calls
time.Tick
then closes the go routines down again in an orderly fashionhttp://play.golang.org/p/zy5X4hAq0I
It sleeps at the end so you can run top or equivalent and see that it will be using 100% of a CPU core keeping the
Ticker
s up to date even though the user no longer has access to them.This is unfortunate but it was decided in #8001 that it was too difficicult to
Stop
theTicker
s when they are garbage collected.The documentation for
NewTicker
got changed after this, but not the documentation forTick
.It currently reads
It doesn't say why you might want to shut the Ticker down.
My suggestion for a re-word is this
That is possibly too alarmist, but I wanted the docs to note clearly that using
time.Tick
is leaking something which can't be recovered.The text was updated successfully, but these errors were encountered: