像下面的代码这样的简单 goroutine 通过停止计时器而停止,它会变得干净吗?还是一直留在记忆中直到程序结束?go func() {
<-timer1.C //Will stop before firing.
fmt.Println("Timer 1 fired")
}()
1 回答

12345678_0001
TA贡献1802条经验 获得超5个赞
如果通道关闭,Go 例程将退出。如果频道保持打开状态,但没有任何内容通过它发送,那么 Go 例程将永远“挂起”,直到程序退出。
如果 是 ,则不会关闭通道,如文档中所述:https://pkg.go.dev/time#Timer.Stoptimer1
time.Timer
Stop
- 1 回答
- 0 关注
- 102 浏览
添加回答
举报
0/150
提交
取消