網(wǎng)站開發(fā)難學(xué)嗎學(xué)生個人網(wǎng)頁優(yōu)秀模板
Goroutine沒有順利結(jié)束
1、這里更多的是由于channel+for+select導(dǎo)致的,錯誤的寫法導(dǎo)致了發(fā)送者或接收者沒有發(fā)現(xiàn)channel已經(jīng)關(guān)閉,任務(wù)已經(jīng)結(jié)束了,卻仍然在嘗試輸入輸出https://geektutu.com/post/hpg-exit-goroutine.html
Map的remove方法不會真正的刪除某個key,內(nèi)存會無限增長
不要把map用作全局
timer的錯誤用法
//錯誤用法
for{select {//這里timer會生成一個新變量,在timer到期之前會一直占用內(nèi)存case <-time.After(duration):fmt.Println("process request with", duration)}}
//正確用法
idleDelay := time.NewTimer(idleDuration)
defer idleDelay.Stop()
for{idleDelay.Reset(idleDuration)select {case <-idleDelay.C:fmt.Println("process request with", duration)}}