-
Notifications
You must be signed in to change notification settings - Fork 596
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
Is there a memory leak in bigcache? #369
Comments
You need to specify Lines 25 to 32 in caa3415
Lines 57 to 67 in caa3415
|
@janisz, but why cache will only grow even if the number of key/value pairs is constant all the time and the content (both key and values) that I am setting again after removing is also exactly the same? I understand that there might be some additional space requirements by library itself for internal handling (overhead as mentioned in the comments of |
I also tried the same above script with various other Go in-memory caching libraries like go-cache, ttl-cache and even the native Go maps. Non of them are showing this much fluctuation. Also, the total memory footprint is also way higher in bigcache. So I was wondering if there is any specific reason for that? |
I could find many other similar open issues/bug stating almost the same problem as I mentioned: From all these, it seems that when over writing existing key with same value or deleting keys would not actually delete the existing value and will keep adding new content to the cache and it's intentional. So we must set max hard limit to cache size |
I initially set a 10k keys and then for multiple times, I cleared half of them and set them again. In total the number of keys are constant (10k) all the time and all the key names and values are exactly the same. I just
Delete()
andSet()
the same keys multiple times on the same bigcache instance.When I did this 5 times, the memory profile (pprof) showed total of ~396MB memory being allocated at the end. But When I did the same 25 time, it showed ~2.26GB memory still allocated. Since I am clearing and then re-setting the key value pairs, shouldn't the memory utilization be same irrespective of number of time I do it as long as the key-value pair content and number of key-values are exactly same?
Why memory utilization increases as I do more
Delete
andSet
?Here is the script that I used to do it for better understanding and reproducibility:
Note that I am using
github.com/allegro/bigcache/v2 v2.2.5
and this profiling is fromhttp://localhost:6060/debug/pprof/heap
Here is the mem profile result when I did it 25 times:
Here is the mem profile result when I did it 5 times:
Notice the difference in the memory utilization above. Is that a sign on memory leak? Please help.
The text was updated successfully, but these errors were encountered: