golang time.After 內存泄漏
互聯網 2022/4/30 7:13:05
官方一段話 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 }
結論
- until the timer fires,說明fire后是會被回收的,fire就是到時間了
一個問題就在 死循環或者 select 使用 time.After
case <- time.After(time.Second) : // 只是子本次只有在本次select 操作中會有效, 再次select 又會重新開始計時(從當前時間1秒后), 但是有default ,那case 超時操作,肯定執行不到了

關于找一找教程網
本站文章僅代表作者觀點,不代表本站立場,所有文章非營利性免費分享。
本站提供了軟件編程、網站開發技術、服務器運維、人工智能等等IT技術文章,希望廣大程序員努力學習,讓我們用科技改變世界。
[golang time.After 內存泄漏]http://www.yachtsalesaustralia.com/tech/detail-318192.html
- 2022-05-03beego 獲取POST Payload 參數
- 2022-05-03(四)Golang導入本地包
- 2022-05-02mongodb4.4 "errmsg" : "command insert requires authentication"
- 2022-05-02Go 將引入快速排序算法 pdqsort
- 2022-05-02PgoOps運維平臺部署文檔
- 2022-04-30使用Django的auth模塊內置的密碼加密方法
- 2022-04-30GO語言學習——切片三 append()方法為切片添加元素、切片的擴容策略、使用copy()函數復制切片、從切片中刪除元素
- 2022-04-30解決django.core.exceptions.ImproperlyConfigured: Cannot import 'book.apps.users'. Check that
- 2022-04-29golang goroutine 父子關系
- 2022-04-29Go圣經學習筆記——底層編程