Professional Documents
Culture Documents
Garbage Collection Algorithms: by Achinth Anand Gurkhi
Garbage Collection Algorithms: by Achinth Anand Gurkhi
Garbage Collection Algorithms: by Achinth Anand Gurkhi
Reference Counting
Mark-Sweep Collector
Copying Collector
Mark-Compact Collector
Generational Collector
Reference Counting
Advantages:
Garbage collection can be immediate
Disadvantages:
Cannot handle cyclic references
Need extra memory for the reference counter
Incrementing and decrementing reference counts every time a
reference is created or destroyed can significantly impede
performance. Example: array processing
Mark-Sweep Collector
Advantages:
Can handle cyclic references
No burden on the compiler or the application
Disadvantages
As entire heap is scanned, pauses would be longer
If heap is paged can have performance issues
Causes heap fragmentation which could lead of out of memory
errors
Copying Collector
Advantages:
Only live objects are visited, garbage objects are not visited
Data compaction is achieved which reduces cost of object
allocation and out of memory errors
Disadvantages:
Requires twice the heap size than other collectors
Overhead of copying objects from one space to another
Overhead of adjusting all references to the new copy
Long lived objects are copied back and forth on every collection
Mark-Compact Collector
Advantages:
Compaction is achieved
Without the hassle of long lived objects being copied back and forth
Without the need for double the heap size
Disadvantages
Overhead of copying objects (for compaction)
Overhead of adjusting all references to the new copy
Generational Collector
Advantages:
GC cycles are small as all objects are not collected
Only old objects are copied from one generation to another
Entire heap is not scanned
Disadvantages
Overhead of copying objects (for compaction)
Overhead of adjusting all references to the new copy