Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time: stop time.Ticker when it is garbage collected #8001

Closed
gopherbot opened this issue May 15, 2014 · 6 comments

Comments

Projects
None yet
4 participants
@gopherbot
Copy link

commented May 15, 2014

by awawfumin:

Go version:

> go version
go version go1.2.2 darwin/amd64

After reading the source code http://golang.org/src/pkg/runtime/time.goc , and later
confirmed by Ian Lance Taylor
https://groups.google.com/d/msg/golang-nuts/Chx1tCs2QGg/EbEOnm18NF0J , the current
implementation of time.Ticker would leak memory in the global structure
"timers" if the Ticker is no longer referenced.

We should preferably Stop() a Ticker when it is garbage collected, or if that is
technically not feasible at the moment, at least document in
http://golang.org/pkg/time/#Ticker much like how it is emphasized to call Close() after
reading from resp.Body http://golang.org/pkg/net/http/#Client.Get .

More info about the problem, plus several possible implementation proposals (to date
none are satisfactory) can be found in
https://groups.google.com/forum/#!topic/golang-nuts/Chx1tCs2QGg
@pmezard

This comment has been minimized.

Copy link
Contributor

commented May 15, 2014

Comment 1:

FWIW, the documentation part was addressed by
https://code.google.com/p/go/source/detail?r=7e130e3f9a4f
@gopherbot

This comment has been minimized.

Copy link
Author

commented May 15, 2014

Comment 2 by robryk:

Unfortunately, we can't stop a Ticker when it's GCed. A user can hold on to a copy of
the timer from the Ticker and allow the Ticker to be garbage collected. In that case, we
don't want to stop the Ticker. In fact, Tick does exactly that.
As far as I know, there is no way to notice when the channel itself is destroyed (I
don't mean a value of type chan, but the channel that backs it). Thus, I don't see any
way of noticing when a Ticker isn't used anymore.
@gopherbot

This comment has been minimized.

Copy link
Author

commented May 15, 2014

Comment 3 by robryk:

s/a copy of the timer/a copy of the channel/
@gopherbot

This comment has been minimized.

Copy link
Author

commented May 16, 2014

Comment 4 by awawfumin:

I see, there's indeed a lot of complications here. Nevertheless, I think the
documentation enhancement in https://code.google.com/p/go/source/detail?r=7e130e3f9a4f
looks good. Hopefully, it can be incorporated in http://golang.org/pkg/time/#Ticker soon.
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented May 16, 2014

Comment 6:

That doc sentence is already there on tip.golang.org.  It will move to golang.org when
1.3 is released.
@rsc

This comment has been minimized.

Copy link
Contributor

commented May 21, 2014

Comment 7:

Status changed to Unfortunate.

This issue was closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.