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
Closed

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

gopherbot opened this issue May 15, 2014 · 6 comments

Comments

@gopherbot
Copy link

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
Copy link
Contributor

pmezard commented May 15, 2014

Comment 1:

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

@gopherbot
Copy link
Author

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
Copy link
Author

Comment 3 by robryk:

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

@gopherbot
Copy link
Author

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
Copy link
Contributor

Comment 6:

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

@rsc
Copy link
Contributor

rsc 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.
Projects
None yet
Development

No branches or pull requests

4 participants