Skip to content
 

Adding a garbage collector

I guess it is clear by now that I am writing a toy Scheme compiler and virtual machine. Primarily for learning the techniques, I just touch it from time to time. The last addition to the virtual machine was a Cheney-style copy garbage collector. I wanted to implement a very simple algorithm to get a functioning system quicker. The simplest algorithms I know of are the Cheney one and the Deutsch-Schorr-Waite mark-and-sweep garbage collector. I chose the copying one because I believe generational garbage collection is the way to go for Scheme virtual machines, given that the rate of allocation is very high (allocation in a copy garbage collector is just moving a pointer) and most data objects die young (how many times did you use reverse after a loop?).

I was surprised by how easy it was to implement the collector. It is a very simple one (stop-the-world, two semi-spaces etc.) but nevertheless I always thought garbage collectors were somewhat magical, a bunch of elves that worked out of sight to keep your process working perfectly. This is exactly why I am writing such a system, even if it never gets free onto the world it will fulfill its purpose. Of course, if I am satisfied with the result, I will release the beast.

One Comment

  1. James Long says:

    Cheers! I’ve always wanted to build a sample Scheme compiler myself. I hope to get around to it sometime.

    Found your blog from the gambit list, by the way. Did you ever find work? I’m hoping to start writing some iPhone games in Gambit Scheme later this summer. Let me know if you’re interested in taking part.

Leave a Reply