visaljs

Garbage Collector

JavaScript is garbage collected. A program creates strings, objects and arrays whenever it likes, and never says when it’s done with them. The engine frees the memory nobody uses anymore, on its own.

C has none of that. In Strings, every string calls malloc, and nothing ever calls free. A program that runs long enough runs out of memory. So visaljs brings its own garbage collector, as part of the runtime. The C code the compiler emits doesn’t even know it’s there.

Over the next chapters, we build it step by step.

Read more: runtime/src/gc.c