Marking live data and sweeping the rest
This section gives an overview of the Unicon garbage collector, which is a mark-and-sweep style of garbage collector that was developed for the Icon language and then extended. It is written in (an extended dialect of) C, like the rest of the Icon and Unicon runtime system. Since Unicon inherited this garbage collector from Icon, much of what you see here is due to that language. Other aspects of this garbage collector are described in the book, The Implementation of Icon and Unicon: a Compendium.
In almost all garbage collectors other than reference counting, the approach is to find all the live pointers that are reachable from all the variables in the program; everything else in the heap is garbage. In a mark-and-sweep collector, live data is marked when it is found, and then all the live data is moved up to the top of the heap, leaving a big, beautiful pool of newly available memory at the bottom. The collect()
C function from Unicon&apos...