Garbage Collection
Garbage Collection
Garbage Collection
The name "garbage collection" implies that objects that are no longer needed by the program are "garbage" and can be thrown away. A garbage collector automatically searches out garbage and reallocates it Practically every modern language, except C/C++, uses a garbage collector
Garbage Collection
What is garbage and how can we deal with it?
Mark-and-sweep
Stop-and-copy garbage collection.
Count for each object. Count increases as number of reference increases. Eligible for GC when count equals zero. Disadvantages Overhead of incrementing and decrementing reference count.
Generational Collectors
Based on lifetimes of objects. Short lived objects Long lived objects Collection of short lived objects done more often. Heap is divided into two or more sub heaps Objects are promoted to different heaps based on survival.