0
votes

While going through garbage collection, I came across Reference Counting and Mark & Sweep GC Algorithms.
Some research on the web says that Reference Counting is a thing of the past and most of the browsers today have adapted Mark and Sweep. As per the article here

Since 2012, JavaScript Engine’s have adapted this algorithm over Reference-counting garbage collection.

While I haven't found any standard documentation for the same, I am curioud to know following:

  1. Was there any other reason other than cyclic dependency that made us move away from Reference Counting and adopt Mark & Sweep?
  2. Do all modern browsers (Chrome | Firefox | Safari | Edge | IE) use Mark and Sweep?
1
IE is not a modern browser, but yes it still uses Mark and Sweep.Bergi
No, most browsers have moved on from the basic mark and sweep algorithm, but they still use a tracing GC approach. Reference cycles have never been a problem in JS, except from one bug in the DOM implementation of IE.Bergi
Thanks @Bergi! Did we ever use Reference Counting?Green goblin

1 Answers

2
votes

Quoting MDN

As of 2012, all modern browsers ship a mark-and-sweep garbage-collector. All improvements made in the field of JavaScript garbage collection (generational/incremental/concurrent/parallel garbage collection) over the last few years are implementation improvements of this algorithm, but not improvements over the garbage collection algorithm itself nor its reduction of the definition of when "an object is no longer needed".