3 ms·
Apparently the garbage collection algorithm is reference counting with cycle removal: https://bellard.org/quickjs/quickjs.html#Garbage-collection https://bellar
by saagarjha 7y ago
Apparently the garbage collection algorithm is reference counting with cycle removal: https://bellard.org/quickjs/quickjs.html#Garbage-collection https://bellard.org/quickjs/quickjs.html#Garbage-collection. Swift does pure reference counting, relying on the programmer to annotate references so that there are no cycles (which is untenable in JavaScript, due to the way the language is designed).
- aspirin 7y agoCurious what ”The cycle removal algorithm only uses the reference counts and the object content” means in practice. Is it based on some well known algorithm?
- pcwalton 7y agoFrom the description it's probably a Bacon cycle collector. The basic idea is that it checks to see whether reference counts for all objects in a subgraph of the heap are fully accounted for by other objects in that subgraph. If so, then it's a cycle, and you can delete one of the edges to destroy the cycle. Otherwise, one of the references must be coming from "outside" (typically, the stack) and so the objects cannot be safely destroyed. It's a neat algorithm because you don't have to write a stack scanner, which is one of the most annoying parts of a tracing GC to write.