0

I'm caching an object in the global namespace so for example: global.cachedObject = myObject;

but I notice that after a certain amount of time, node garbage collects it. Is there a way to tag the object in some way so that it doesn't get collected?

Shai UI
  • 50,568
  • 73
  • 204
  • 309
  • This might help http://stackoverflow.com/questions/5733665/how-to-prevent-memory-leaks-in-node-js – Chetan Bhasin May 20 '14 at 15:36
  • Bugs or very obscure edge cases nonwithstanding, only unreachable objects are GC'd. Is your object unreachable? If so, *your code* has a bug (if it's unreachable it can't be used for caching). If not, please provide more details. How do you determine that it's collected? –  May 20 '14 at 15:38
  • Well yeah, it's not used or referenced. Sometimes I just reference this object on an http GET request (to return it). I wanted to know how to force an object to stay. – Shai UI May 20 '14 at 15:58

0 Answers0