Closed vladar closed 3 years ago
I didn't realize that the cache
option could be an object with all the options from https://github.com/kriszyp/weak-lru-cache
By setting cache: { cacheSize: number }
or cache: { expirer: false }
I can control the behavior. Sorry for the noise.
Some context first - occasionally we need to iterate over big ranges of keys and fetch value by key on each step. Without
cache: true
we see the expected behavior of garbage collection - unused objects are released during iteration.But when I enable caching - memory keeps growing and nothing seems to be garbage-collected during iteration. And even after forced gc - something is retained in memory.
Not sure if it is a bug or expected behavior but if it is expected - then it is not entirely clear when garbage collection actually kicks-in.
Here is a test script: https://gist.github.com/vladar/046bae076d8d42f802fb520e7ff8b226
Running without cache (
node --expose-gc gc-test.js
):Running with cache (
CACHE=1 node --expose-gc gc-test.js
):