dovs36921 2017-02-23 16:03
浏览 155
已采纳

time.NewTimer vs time.Tick

The documentation indicates the time.Tick leaks ('be aware that without a way to shut it down the underlying Ticker cannot be recovered by the garbage collector; it "leaks"'). I'm assuming this refers to the channel. However, there appears to be no way to cleanup a Timer, either: You can make sure it doesn't fire but you can't close the channel (receive only).

The code for it doesn't contain a close call. runtime.deltimer (which is the underlying mechanism for Stop) doesn't touch the channel either.

No matter what, does Timer always leak?

  • 写回答

1条回答 默认 最新

  • dqqfuth6736 2017-02-23 16:16
    关注

    The only cleanup that matters is performed by calling Stop (as mentioned by @JimB).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?