node-lru-cache icon indicating copy to clipboard operation
node-lru-cache copied to clipboard

Memory is not released on dispose causing OOM

Open OverLord561 opened this issue 1 year ago • 3 comments

Hi Folks!

I am using [email protected] + [email protected] like below: image

Value - huge object, generated during Server Side Rendering.

The problem:

  • memory is not released on dispose
  • adding new items evict old entities but the total memory is slowly growing, causing OOM
  • ttlAutopurge: true expires the entities but does not release the memory

Possible way to release memory:

  • manually clear the cache inside setTimeout() which is not the option

What is the best memory releasing strategy?

Thanks in advance!

OverLord561 avatar Dec 03 '24 16:12 OverLord561

I`d like to add that I use express.js app. I simulate high load by executing simple HTTP request like setTimeout(() => {executor()}, 100).

From the logs I see that not all LRU items are properly evicted.

Every time all the items are supposed to be expired and pruned but a few are still in the memory. image

OverLord561 avatar Dec 04 '24 11:12 OverLord561

Identified that the items are not properly evicted due to updateAgeOnGet & updateAgeOnHas presence.

OverLord561 avatar Dec 05 '24 14:12 OverLord561

@OverLord561 did you manage to fix or properly workaround the issue? I see:

  • https://github.com/isaacs/node-lru-cache/issues/227 which says setting maxSize should fix it
  • might be a V8 bug https://github.com/isaacs/node-lru-cache/issues/331#issuecomment-2060094728 (V8 bug still open, created Apr 2024)

shazron avatar Mar 21 '25 02:03 shazron