: the stack empties itself and the heap stays full until someone gives pieces back. This lesson builds the part that finds the pieces nobody needs and gives them back for you.
Before you start. The interpreter in An interpreter of your own keeps names in environments, one per function call, each pointing to its parent, and a function remembers the environment where it was defined. The heap is the work area for anything that must outlive one call (How Code Becomes Execution (compilers, stack & heap)), and A malloc of your own built the part that hands out pieces of it and showed how waste is measured. That allocator trusted the caller to give every piece back. Here nobody has to.
Lesson 112 of 117 in From Scratch
The rest of this lesson is part of a plan.
A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.