Chapter 16: Garbage Collection
Memory management is one of the most important aspects of modern programming, and almost any language that you invent should provide automatic memory management via garbage collection. This chapter presents a couple of methods with which you can implement garbage collection in your language. The first method, called reference counting, is easy to implement and has the advantage of freeing memory as you go. However, reference counting has a fatal flaw. The second method, called mark-and-sweep collection, is a more robust mechanism that is much more challenging to implement, and it has the downside that execution pauses periodically for however long the garbage collection process takes. These are two of many possible approaches to memory management. Implementing a garbage collector with neither a fatal flaw nor periodic pauses to collect free memory is liable to have other costs associated with it.
This chapter covers the following main topics:
-
...