🔮
💻
Magic is just (computer) science you don’t understand yet
Slide 6
Slide 7
Slide 8
Slide 9
🧠 Allocate memory
Slide 10
🧠 🔍 Allocate memory
Find the garbage
Slide 11
🧠 🔍 🗑 Allocate memory
Find the garbage
Free up memory
Slide 12
Slide 13
📚 Running out of memory
Slide 14
📚
🔥
Running out of memory
Breaking things
Slide 15
DANGLING POINTERS
Slide 16
DANGLING POINTERS
Slide 17
DANGLING POINTERS
🔥
Slide 18
DANGLING POINTERS
🔥 Memory Leak
Slide 19
REFERENCE COUNTING If nothing points to it, nothing’s using it
Slide 20
REFERENCE COUNTING
Slide 21
REFERENCE COUNTING name = “Ruby”
Slide 22
REFERENCE COUNTING name name = “Ruby” “Ruby”
1
Slide 23
REFERENCE COUNTING name name = “Ruby” other_name = name
“Ruby”
1
Slide 24
REFERENCE COUNTING name name = “Ruby” other_name = name
“Ruby”
other_name
2
Slide 25
REFERENCE COUNTING name name = “Ruby” other_name = name
“Ruby”
name = nil other_name
2
Slide 26
REFERENCE COUNTING name name = “Ruby” other_name = name
“Ruby”
name = nil other_name
1
Slide 27
REFERENCE COUNTING name name = “Ruby” other_name = name
“Ruby”
name = nil other_name = nil other_name
1
Slide 28
REFERENCE COUNTING name name = “Ruby” other_name = name
“Ruby”
name = nil other_name = nil other_name
0
Slide 29
REFERENCE COUNTING name name = “Ruby” other_name = name
“Ruby”
name = nil other_name = nil other_name
0
Slide 30
CYCLES
Slide 31
CYCLES a = { other: nil }
Slide 32
CYCLES a = { other: nil }
a
{ other: nil }
1
Slide 33
CYCLES a = { other: nil } b = { other: a }
a
{ other: nil }
1
Slide 34
CYCLES a = { other: nil }
a
{ other: nil }
1
b
{ other: a }
1
b = { other: a }
Slide 35
CYCLES a = { other: nil }
a
{ other: nil }
2
b
{ other: a }
1
b = { other: a }
Slide 36
CYCLES a = { other: nil }
a
{ other: nil }
2
b
{ other: a }
1
b = { other: a } a[:other] = b
Slide 37
CYCLES a = { other: nil }
a
{ other: b }
2
b
{ other: a }
1
b = { other: a } a[:other] = b
Slide 38
CYCLES a = { other: nil }
a
{ other: b }
2
b
{ other: a }
2
b = { other: a } a[:other] = b
Slide 39
CYCLES a = { other: nil }
a
{ other: b }
2
b
{ other: a }
2
b = { other: a } a[:other] = b a = nil b = nil
Slide 40
CYCLES a = { other: nil }
a
{ other: b }
1
b
{ other: a }
2
b = { other: a } a[:other] = b a = nil b = nil
Slide 41
CYCLES a = { other: nil }
a
{ other: b }
1
b
{ other: a }
1
b = { other: a } a[:other] = b a = nil b = nil
Slide 42
MARK & SWEEP If you can’t get to it, you can’t be using it
Slide 43
Slide 44
MARK & SWEEP
Slide 45
MARK & SWEEP
Slide 46
MARK & SWEEP
Slide 47
MARK & SWEEP
Slide 48
MARK & SWEEP
Slide 49
MARK & SWEEP
Slide 50
MARK & SWEEP
Slide 51
MARK & SWEEP
Slide 52
MARK & SWEEP
Slide 53
MARK & SWEEP
Slide 54
MARK & SWEEP
Slide 55
MARK & SWEEP
Slide 56
COPYING COLLECTION Keep your stuff together
Slide 57
COPYING COLLECTION FROM Space
TO Space
0
1
2
3
4
5
6
7
8
Slide 58
COPYING COLLECTION FROM Space
0
TO Space
0
1
2
3
4
5
6
7
8
Slide 59
COPYING COLLECTION FROM Space
0
1
TO Space
0
2
2
3
4
5
6
7
8
Slide 60
COPYING COLLECTION FROM Space
0
1
2
TO Space
0
2
3
3
4
5
6
7
8
Slide 61
COPYING COLLECTION FROM Space
0
1
2
3
TO Space
0
2
3
4
4
5
6
7
8
Slide 62
COPYING COLLECTION FROM Space
0
1
2
3
4
TO Space
0
2
3
4
5
5
6
7
8
Slide 63
COPYING COLLECTION FROM Space
0
1
2
3
4
5
TO Space
0
2
3
4
5
7
6
7
8
Slide 64
COPYING COLLECTION FROM Space
0
TO Space
0
2
2
3
4
5
3
4
5
7
7
Slide 65
COPYING COLLECTION FROM Space
0
TO Space
0
2
2
3
4
5
3
4
5
7
7
Slide 66
GENERATIONAL COLLECTION If you’ve been using it for a while, it’s probably important
Slide 67
GENERATIONAL COLLECTION New objects
Old objects
D
Slide 68
GENERATIONAL COLLECTION New objects
Old objects
D
Slide 69
GENERATIONAL COLLECTION New objects
Old objects
D
Slide 70
GENERATIONAL COLLECTION New objects
Old objects
D
Slide 71
GENERATIONAL COLLECTION New objects
Old objects
D
Slide 72
GENERATIONAL COLLECTION New objects
Old objects
D
Slide 73
GENERATIONAL COLLECTION New objects
Old objects
D
Slide 74
GENERATIONAL COLLECTION New objects
Old objects
D
Slide 75
GENERATIONAL COLLECTION New objects
Old objects
D
Slide 76
GENERATIONAL COLLECTION New objects
Old objects
D
Slide 77
GENERATIONAL COLLECTION New objects
Old objects
D
Slide 78
GENERATIONAL COLLECTION New objects
Old objects
D
Slide 79
GENERATIONAL COLLECTION New objects
Old objects
D
Slide 80
WHAT ABOUT RUBY? MRI garbage collection
Slide 81
FREE LIST
Slide 82
FREE LIST
Slide 83
FREE LIST
Slide 84
FREE LIST
Slide 85
FREE LIST
Slide 86
FREE LIST
Slide 87
FREE LIST
Slide 88
MARK & SWEEP
Slide 89
MARK & SWEEP
Slide 90
MARK & SWEEP
Slide 91
MARK & SWEEP
Slide 92
MARK & SWEEP
Slide 93
MARK & SWEEP
Slide 94
MARK & SWEEP
Slide 95
MARK & SWEEP
Slide 96
MARK & SWEEP
Slide 97
LAZY SWEEPING
Slide 98
LAZY SWEEPING
Slide 99
LAZY SWEEPING
Slide 100
LAZY SWEEPING
Slide 101
LAZY SWEEPING
Slide 102
LAZY SWEEPING
Slide 103
GENERATIONAL COLLECTION
)
(
Slide 104
GENERATIONAL COLLECTION
)
(
Slide 105
GENERATIONAL COLLECTION
)
(
Slide 106
GENERATIONAL COLLECTION
)
(
Slide 107
GENERATIONAL COLLECTION
)
(
Slide 108
GENERATIONAL COLLECTION
)
(
Slide 109
GENERATIONAL COLLECTION
)
(
Slide 110
GENERATIONAL COLLECTION
)
(
Slide 111
WRITE BARRIERS
Slide 112
WRITE BARRIERS
Slide 113
WRITE BARRIERS
Slide 114
WRITE BARRIERS
Slide 115
WRITE BARRIERS
Slide 116
WRITE BARRIERS
*
Slide 117
Slide 118
☀ Sunny
Slide 119
☀
🕶
Sunny
Shady
Slide 120
🔮
💻
Garbage collection is no longer magic!
Slide 121
LET ME KNOW WHAT YOU THINK! Tweet me @sannekalkman Find me in person later!
The Garbage Collection Handbook - Jones, Hoskin & Moss Ruby Under A Microscope - Pat Shaughnessy