2.2. Garbage Collection
In Java, objects are never explicitly deleted. Instead, Java relies on some form of garbage collection to free memory when objects are no longer in use. The JVM specification [Lindholm and Yellin 1997]requires that every Java runtime implementation should have some form of automatic garbage collection. The specific details of the mechanism are left up to the implementors. A large variety of garbage collection algorithms have been developed, includingreference counting, mark-sweep, mark-compact, copying, and noncopying implicit collection [Wilson 1992]. While these techniques typically halt processing of the application program when garbage collection is needed, incrementalgarbage collection techniques have been developed that allow garbage collection to be interleaved with normal program execution. Another class of techniques known asgenerationalgarbage collection improve efficiency and memory locality by working on a smaller area of memory. These techniques exploit the observation that recently allocated objects are most likely to become garbage within a short period of time. The garbage collection process imposes a time penalty on the user program. Con sequently, it is important that the garbage collector is efficient and interferes with execution as little as possible. From the implementor’s point of view, the programming effort required to implement the garbage collector is another consideration. However, easy-to-implement techniques may not be the most execution time efficient. For example, conservative garbage collectors treat every register and word of allocated memory as a potential pointer and thus do not require any additional type information for allocated memory blocks to be maintained. The drawback, however, is slower execution time.Thus, there are trade-offs between ease of implementation and execution-time performance to be made when selecting a garbage collection technique for the JVM implementation.