Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: memory leak when gcache.NewAdapterMemory with lru #3241

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading