【go】golang time.NewTicker 内存泄漏?
- 程序运行内存不停增加 , 使用 pprof 查看,怀疑是time.NewTicker问题
部分代码
func (spider *Spider) downloaderTotalPlatform() {rconn := redis.GetConn()
defer rconn.Close()
queue := db.Queue{}
for {
v, err := rconn.Do("LPOP", db.RedisListList)
if err != nil {
log.Println(err.Error())
continue
}
if v == nil {
//暂停 5 秒
<-time.Tick(time.Second * 5)
continue
}
body, err := downloaders(v, &queue)
if err != nil {
log.Println(err.Error())
continue
}
if body == nil {
continue
}
spider.ChanParsers <- &Parser{
Body:body,
Queue:queue,
}
}
}
pprof图:
看看Tick的注释就知道了:
// Tick is a convenience wrapper for NewTicker providing access to the ticking// channel only. While Tick is useful for clients that have no need to shut down
// the Ticker, be aware that without a way to shut it down the underlying
// Ticker cannot be recovered by the garbage collector; it "leaks".
回答
以上是 【go】golang time.NewTicker 内存泄漏? 的全部内容, 来源链接: utcz.com/a/113375.html