Hacker News new | past | comments | ask | show | jobs | submit login

I'm curious as to how the reference counting works in this. Is it comparable to what's used in Swift? How is it compared to the methods typically used in V8 and Spider Monkey?



Apparently the garbage collection algorithm is reference counting with cycle removal: 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).


Curious 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?


From 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.


This is a very broad question. Garbage collection is a large topic. The general consensus is that reference counting methods give typically lower throughput than heap scanning methods but (I think) lower total memory usage and more predictable performance.

They do bookkeeping on every free whereas a heap scanning gc will typically do bookkeeping in small incremental bits on alloc and mainly on gc cycle (when space runs low).


Would also be interesting to see how this GC runs in threaded or multi-instance environment. For example, Nim (the language) can produce libs by having them link to one dynamic lib containing the RT. Other compilers, like Crystal, don't support this outright.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: