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).

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

报告相同问题?

悬赏问题

  • ¥15 vs2022无法联网
  • ¥15 TCP的客户端和服务器的互联
  • ¥15 VB.NET操作免驱摄像头
  • ¥15 笔记本上移动热点开关状态查询
  • ¥85 类鸟群Boids——仿真鸟群避障的相关问题
  • ¥15 CFEDEM自带算例错误,如何解决?
  • ¥15 有没有会使用flac3d软件的家人
  • ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
  • ¥15 docker实践项目
  • ¥15 利用pthon计算薄膜结构的光导纳