From e7bacd0f127fcde1399f92452bd0039f58916fed Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 19 Nov 2018 10:57:53 +0800 Subject: [PATCH] Possible memory leak because of Ticker --- pool.go | 2 ++ pool_func.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/pool.go b/pool.go index 36fe5cb..4c7309f 100644 --- a/pool.go +++ b/pool.go @@ -62,6 +62,8 @@ type Pool struct { // clear expired workers periodically. func (p *Pool) periodicallyPurge() { heartbeat := time.NewTicker(p.expiryDuration) + defer heartbeat.Stop() + for range heartbeat.C { currentTime := time.Now() p.lock.Lock() diff --git a/pool_func.go b/pool_func.go index fbcbe9d..5c46689 100644 --- a/pool_func.go +++ b/pool_func.go @@ -63,6 +63,8 @@ type PoolWithFunc struct { // clear expired workers periodically. func (p *PoolWithFunc) periodicallyPurge() { heartbeat := time.NewTicker(p.expiryDuration) + defer heartbeat.Stop() + for range heartbeat.C { currentTime := time.Now() p.lock.Lock()