Skip to content

Commit

Permalink
fix: memory leak when gcache.NewAdapterMemory with lru (#3241)
Browse files Browse the repository at this point in the history
  • Loading branch information
qinyuguang authored Jan 3, 2024
1 parent 8af1eb6 commit 5a01798
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
3 changes: 3 additions & 0 deletions os/gcache/gcache_adapter_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ func NewAdapterMemory(lruCap ...int) Adapter {
c.cap = lruCap[0]
c.lru = newMemCacheLru(c)
}
// Here may be a "timer leak" if adapter is manually changed from memory adapter.
// Do not worry about this, as adapter is less changed, and it does nothing if it's not used.
gtimer.AddSingleton(context.Background(), time.Second, c.syncEventAndClearExpired)
return c
}

Expand Down
5 changes: 0 additions & 5 deletions os/gcache/gcache_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ package gcache

import (
"context"
"time"

"github.com/gogf/gf/v2/os/gtimer"
"github.com/gogf/gf/v2/util/gconv"
)

Expand All @@ -29,9 +27,6 @@ func New(lruCap ...int) *Cache {
c := &Cache{
localAdapter: memAdapter,
}
// Here may be a "timer leak" if adapter is manually changed from memory adapter.
// Do not worry about this, as adapter is less changed, and it does nothing if it's not used.
gtimer.AddSingleton(context.Background(), time.Second, memAdapter.(*AdapterMemory).syncEventAndClearExpired)
return c
}

Expand Down

0 comments on commit 5a01798

Please # to comment.