WHO TAKES OUT YOUR TRASH? @sannekalkman

đź”®

đź”® đź’»

🔮 💻 Magic is just (computer) science you don’t understand yet

đź§  Allocate memory

🧠 🔍 Allocate memory Find the garbage

🧠 🔍 🗑 Allocate memory Find the garbage Free up memory

📚 Running out of memory

📚 🔥 Running out of memory Breaking things

DANGLING POINTERS

DANGLING POINTERS

DANGLING POINTERS 🔥

DANGLING POINTERS 🔥 Memory Leak

REFERENCE COUNTING If nothing points to it, nothing’s using it

REFERENCE COUNTING

REFERENCE COUNTING name = “nodefest”

REFERENCE COUNTING name name = “nodefest” “nodefest” 1

REFERENCE COUNTING name name = “nodefest” other_name = name “nodefest” 1

REFERENCE COUNTING name name = “nodefest” other_name = name “nodefest” other_name 2

REFERENCE COUNTING name name = “nodefest” other_name = name “nodefest” name = nil other_name 2

REFERENCE COUNTING name name = “nodefest” other_name = name “nodefest” name = nil other_name 1

REFERENCE COUNTING name name = “nodefest” other_name = name “nodefest” name = nil other_name = nil other_name 1

REFERENCE COUNTING name name = “nodefest” other_name = name “nodefest” name = nil other_name = nil other_name 0

REFERENCE COUNTING name name = “nodefest” other_name = name “nodefest” name = nil other_name = nil other_name 0

CYCLES

CYCLES a = { other: nil }

CYCLES a = { other: nil } a { other: nil } 1

CYCLES a = { other: nil } b = { other: a } a { other: nil } 1

CYCLES a = { other: nil } a { other: nil } 1 b { other: a } 1 b = { other: a }

CYCLES a = { other: nil } a { other: nil } 2 b { other: a } 1 b = { other: a }

CYCLES a = { other: nil } a { other: nil } 2 b { other: a } 1 b = { other: a } a[:other] = b

CYCLES a = { other: nil } a { other: b } 2 b { other: a } 1 b = { other: a } a[:other] = b

CYCLES a = { other: nil } a { other: b } 2 b { other: a } 2 b = { other: a } a[:other] = b

CYCLES a = { other: nil } a { other: b } 2 b { other: a } 2 b = { other: a } a[:other] = b a = nil b = nil

CYCLES a = { other: nil } a { other: b } 1 b { other: a } 2 b = { other: a } a[:other] = b a = nil b = nil

CYCLES a = { other: nil } a { other: b } 1 b { other: a } 1 b = { other: a } a[:other] = b a = nil b = nil

MARK & SWEEP If you can’t get to it, you can’t be using it

MARK & SWEEP

MARK & SWEEP

MARK & SWEEP

MARK & SWEEP

MARK & SWEEP

MARK & SWEEP

MARK & SWEEP

MARK & SWEEP

MARK & SWEEP

MARK & SWEEP

MARK & SWEEP

MARK & SWEEP

COPYING COLLECTION Keep your stuff together

COPYING COLLECTION 0 1 2 3 4 5 6 7 8

COPYING COLLECTION 0 0 1 2 3 4 5 6 7 8

COPYING COLLECTION 0 1 0 2 2 3 4 5 6 7 8

COPYING COLLECTION 0 1 2 0 2 3 3 4 5 6 7 8

COPYING COLLECTION 0 1 2 3 0 2 3 4 4 5 6 7 8

COPYING COLLECTION 0 1 2 3 4 0 2 3 4 5 5 6 7 8

COPYING COLLECTION 0 1 2 3 4 5 0 2 3 4 5 7 6 7 8

COPYING COLLECTION 0 0 2 2 3 4 5 3 4 5 7 7

COPYING COLLECTION 0 0 2 2 3 4 5 3 4 5 7 7

GENERATIONAL COLLECTION If you’ve been using it for a while, it’s probably important

GENERATIONAL COLLECTION New objects Old objects D

GENERATIONAL COLLECTION New objects Old objects D

GENERATIONAL COLLECTION New objects Old objects D

GENERATIONAL COLLECTION New objects Old objects D

GENERATIONAL COLLECTION New objects Old objects D

GENERATIONAL COLLECTION New objects Old objects D

GENERATIONAL COLLECTION New objects Old objects D

GENERATIONAL COLLECTION New objects Old objects D

GENERATIONAL COLLECTION New objects Old objects D

GENERATIONAL COLLECTION New objects Old objects D

GENERATIONAL COLLECTION New objects Old objects D

GENERATIONAL COLLECTION New objects Old objects D

GENERATIONAL COLLECTION New objects Old objects D

đź”® đź’» Garbage collection is no longer magic!

LET ME KNOW WHAT YOU THINK! Tweet me @sannekalkman Find me in person later! The Garbage Collection Handbook - Jones, Hoskin & Moss