Comments (5)
The test counts the number of goroutines at the beginning and at the end. You need to clean up the memory (garbage collection) before terminating the test. Golang typically does this with a delay. Before releasing an object from memory, the Golang calls a finalizer that terminates the goroutine.
Finalizer registration in code: https://github.com/patrickmn/go-cache/blob/master/cache.go#L1123
About finalizer: https://medium.com/a-journey-with-go/go-finalizers-786df8e17687
About garbage collection: https://tip.golang.org/doc/gc-guide
from go-cache.
it's work
import (
"runtime"
"testing"
"time"
"github.com/patrickmn/go-cache"
"go.uber.org/goleak"
)
func leaktest(t *testing.T) {
defer goleak.VerifyNone(t)
cache.New(5*time.Minute, 10*time.Minute)
runtime.GC()
}
func main() {
testSuite := []testing.InternalTest{{Name: "leaktest", F: leaktest}}
testing.Main(func(a, b string) (bool, error) { return a == b, nil }, testSuite, nil, nil)
}
from go-cache.
I am also getting the similar kind of error as follows
range_service | goroutine 876 [select, 2 minutes]:
range_service | github.com/patrickmn/go-cache.(*janitor).Run(0xc001627fb0, 0xc0011b9140?)
range_service | /Users/jay/go/pkg/mod/github.com/patrickmn/[email protected]+incompatible/cache.go:1079 +0x85
range_service | created by github.com/patrickmn/go-cache.runJanitor
range_service | /Users/jay/go/pkg/mod/github.com/patrickmn/[email protected]+incompatible/cache.go:1099 +0xed
range_service |
range_service | goroutine 877 [select, 5 minutes]:
range_service | github.com/patrickmn/go-cache.(*janitor).Run(0xc001634050, 0x0?)
range_service | /Users/jay/go/pkg/mod/github.com/patrickmn/[email protected]+incompatible/cache.go:1079 +0x85
range_service | created by github.com/patrickmn/go-cache.runJanitor
range_service | /Users/jay/go/pkg/mod/github.com/patrickmn/[email protected]+incompatible/cache.go:1099 +0xed
@vithnilica Can you explain how runtime.GC()
is helping and when to call this function. I am really new to go and don't understand much about memory leaks and all so can you please give an example to explain it better.
Thanks
from go-cache.
It is not memory leaks (or goroutine leak). "go.uber.org/goleak" test does not wait for "garbage collector".
from go-cache.
It is not memory leaks (or goroutine leak). "go.uber.org/goleak" test does not wait for "garbage collector".
Can you please explain why I am getting the error(cause of the error) and how will adding a routine.GC()
after every cache creation helps to resolve the error.
from go-cache.
Related Issues (20)
- Question HOT 1
- please create a new tag HOT 1
- sync.runtime_SemacquireMutex(0xc02c98fbf0?, 0x1f?, 0x3?) HOT 2
- Feature request: Renaming HOT 3
- Recommend a new go-cache package
- why dont exported shardedCache struct? HOT 1
- Question: why Get() function can't unlock immediately?like this: HOT 2
- cache will not expire when system time drift backward
- Float calculation error
- Question About Expired
- Example how to save cache in file and reload using gob an c.Items() ? HOT 1
- The efficiency of `Get` will decrease if too many `Set ` are executed HOT 1
- Introduce pattern-based Keys and Scan functions
- Proposal to Integrate SIEVE Eviction Algorithm
- support generic
- incompatibility Issue
- OnEvicted is not called for every expired value
- go incompatible version HOT 1
- Multiple caches, one metric HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-cache.