Busy Developer's Guide to Garbage Collection

ted.neward@newardassociates.com | Blog: http://blogs.newardassociates.com | Github: tedneward | LinkedIn: tedneward

Objectives

Let's talk about automatic memory management

... aka "garbage collection"

Garbage Collection

What exactly is it?

Garbage Collection

An old truth

Garbage Collection

"Automatic memory management"

Garbage Collection

Automatic memory management tasks:

Garbage Collection

Comparison criteria

Garbage Collection: History

History of an idea

Garbage Collection: History

Automatic memory management is not a new idea

Garbage Collection: Concepts

How do we think about this?

Garbage Collection: Concepts

What's done?

Garbage Collection: Concepts

How/when is it done?

GC Algorithms

4 basic starting points

GC Algorithms

All GC algorithms key off of four basic types:

GC Algorithms

"Second-order"/"hybrid" GC algorithms build on the above

GC Algorithms

Real-world GC implementations base off of these

Mark-Sweep GC

Two-pass garbage collection

Mark-Sweep GC

Mark-Sweep collectors are two-phase collectors

Mark-Sweep GC

Mark Phase: Identifying objects still in use

Mark-Sweep GC

Mark Phase: Root sets

Mark-Sweep GC

Sweep Phase: Reclaim unmarked objects

Mark-Sweep GC

History

Mark-Sweep GC

Questions of note:

Mark-Sweep GC

Consequences:

Copying Collectors

Allocating/reclaiming in large chunks

Copying Collectors

Copying collectors are also two-phase collectors

Copying Collectors

Setup

Copying Collectors

Reclamation

Copying Collectors

Questions of note:

Copying Collectors

Consequences

Mark-Compact GC

Two-phase garbage collection

Mark-Compact GC

Mark-Compact collectors are two-phase collectors

Mark-Compact GC

Mark Phase: Identifying objects still in use

Mark-Compact GC

Mark Phase: Root sets

Mark-Compact GC

Compact Phase: Eliminate "holes"

Mark-Compact GC

Questions of note:

Mark-Compact GC

Consequences (identical to Mark-Sweep):

Mark-Compact GC

Consequences:

Reference Counting

Objects track their own references

Reference Counting

Each object allocated carries with it a "reference count"

Reference Counting

Usage

Reference Counting

Questions of note:

Reference Counting

Consequences:

Reference Counting

Consequences:

Summary

Garbage collection is not a panacea

Garbage Collection: Resources

Where to go to get more

Resources

Books

Resources

Classic papers

Credentials

Who is this guy?