Garbage collection

Posted on
  • So process.memory() does a garbage collection. Does garbage collection happen otherwise?

    Asking because one of my programmes is running out of memory. The programme only has about 2500 bytes available following an initial save() so it is pretty tight.

    It's just doing the same set of operations on a setInterval over and over again at long intervals, and in theory should use approx the same amount of memory each time as it is creating the same variables and not adding to what should be in memory. However after 5 iterations it runs out of memory. Use of process.memory() shows it gradually using more and more after each iteration.

    For now I am simply replacing setInterval with a setTimeout which calls load() as I don't currently need state, however I will in due course.

    I've reviewed the code and I am not obviously storing extra data each time, however i suspect my understanding of good memory management in JS may be weak, and the low memory and high async environment throws that sharply into relief of course.

  • Could you pub some code about the issue? Some references may sttill hang around which keep stuff alive... Can you explain the need for load() by your app?

  • Can you share the code so we can take a look at it and see where it might be leaking?

  • Garbage collection happens whenever Espruino thinks it is idle, but the memory usage reported by processs.memory will always be the usage after Garbage Collection.

    If the memory is rising, it's probably some extra information getting stored. Maybe try running E.getSizeOf(global,2) before and after, and see if you can figure out where the amount of memory used is increasing.

    It is possible it's a memory leak in Espruino, but those are extremely rare now - I haven't come across one in months.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Garbage collection

Posted by Avatar for Moray @Moray

Actions