DEV Community 👩‍💻👨‍💻

Discussion on: How Memory Is Allocated In JavaScript.

jreinhold profile image
Jeppe Reinhold

Great writeup!
Does this mean, that where ever we have circular references, the values will never be garbage collected? Is there any workaround to this, AFAIK we don't have control over the garbage collector in JS?

kelvinkirima014 profile image
Kelvin Kirima Author • Edited on

All modern browsers have a mark and sweep garbage collector. Javascript has come up with ways to improve garbage collection such as:

  1. parallel collection - where the main javascript thread has multiple helper threads help in garbage collection.
  2. incremental collection - all collection is carried by the main thread but in intermittent stages.
  3. concurrent collection - main thread runs javascript code uninterrupted and all garbage collection is done by helper threads. (I should add an article on this) and this means that circular references are no longer a problem. Yes, we don't have control over garbage collection as there is no form of manual garbage collection.