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

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

报告相同问题?

悬赏问题

  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services