17

Garbage Collection

Memory management is one of the most important aspects of modern programming. Almost any language that you invent should provide automatic heap memory management via garbage collection. Garbage collection refers to any mechanism by which heap memory is automatically freed and made available for reuse when it is no longer needed for a given purpose. The heap, as you may already know, is the region in memory from which objects are allocated by some explicit means such as the reserved word new (in Java). In lower-level languages, such objects live until the program explicitly frees them, but in many modern languages, heap objects are retained in memory as long as they are needed. After a heap object is of no further use in ...

Get Build Your Own Programming Language - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.