Previous    Next

Garbage Collection

gar-bage: unwanted or useless material

Webster's Dictionary

OVERVIEW

Heap-allocated records that are not reachable by any chain of pointers from program variables are garbage. The memory occupied by garbage should be reclaimed for use in allocating new records. This process is called garbage collection, and is performed not by the compiler but by the runtime system (the support programs linked with the compiled code). Ideally, we would say that any record that is not dynamically live (will not be used in the future of the computation) is garbage. But, as explains, it is not always possible to know whether a variable is live. So we will use a conservative approximation: We will require the compiler to guarantee that any live record is reachable; we will ask the compiler to minimize the number of reachable records that are not live; and we will preserve all reachable records, even if some of them might not be live. Image 13.1 shows a Java program ready to undergo garbage collection (at the point marked garbage-collect here). There are only three program variables in scope: p, q, and r.

Java Click To expand
Image 13.1: A heap to be garbage collected. Class descriptors are not shown in the diagram.
JaVaScreenshot Previous    Next
Comments