系统相关
首页 > 系统相关> > golang time.After 内存泄漏

golang time.After 内存泄漏

作者:互联网

官方一段话 time.After 内存gc 不会回收
/ After waits for the duration to elapse and then sends the current time
// on the returned channel.
// It is equivalent to NewTimer(d).C.
// The underlying Timer is not recovered by the garbage collector
// until the timer fires. If efficiency is a concern, use NewTimer
// instead and call Timer.Stop if the timer is no longer needed.
func After(d Duration) <-chan Time {
 return NewTimer(d).C
}
结论
一个问题就在 死循环或者 select 使用 time.After
 case <- time.After(time.Second)  :

// 只是子本次只有在本次select 操作中会有效, 再次select 又会重新开始计时(从当前时间1秒后),
 但是有default ,那case 超时操作,肯定执行不到了

标签:fire,After,timer,golang,fires,Timer,time
来源: https://www.cnblogs.com/guanchaoguo/p/16208062.html