Who Takes Out Your Trash?

A presentation at NodeFest in November 2018 in Tokyo, Japan by Sanne Kalkman

Slide 1

Slide 1

WHO TAKES OUT YOUR TRASH? @sannekalkman

Slide 2

Slide 2

Slide 3

Slide 3

đź”®

Slide 4

Slide 4

đź”® đź’»

Slide 5

Slide 5

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

Slide 6

Slide 6

Slide 7

Slide 7

Slide 8

Slide 8

Slide 9

Slide 9

🧠 Allocate memory

Slide 10

Slide 10

🧠 🔍 Allocate memory Find the garbage

Slide 11

Slide 11

🧠 🔍 🗑 Allocate memory Find the garbage Free up memory

Slide 12

Slide 12

Slide 13

Slide 13

đź“š Running out of memory

Slide 14

Slide 14

📚 🔥 Running out of memory Breaking things

Slide 15

Slide 15

DANGLING POINTERS

Slide 16

Slide 16

DANGLING POINTERS

Slide 17

Slide 17

DANGLING POINTERS 🔥

Slide 18

Slide 18

DANGLING POINTERS 🔥 Memory Leak

Slide 19

Slide 19

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

Slide 20

Slide 20

REFERENCE COUNTING

Slide 21

Slide 21

REFERENCE COUNTING name = “nodefest”

Slide 22

Slide 22

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

Slide 23

Slide 23

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

Slide 24

Slide 24

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

Slide 25

Slide 25

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

Slide 26

Slide 26

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

Slide 27

Slide 27

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

Slide 28

Slide 28

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

Slide 29

Slide 29

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

Slide 30

Slide 30

CYCLES

Slide 31

Slide 31

CYCLES a = { other: nil }

Slide 32

Slide 32

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

Slide 33

Slide 33

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

Slide 34

Slide 34

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

Slide 35

Slide 35

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

Slide 36

Slide 36

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

Slide 37

Slide 37

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

Slide 38

Slide 38

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

Slide 39

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

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

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

Slide 42

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

Slide 43

Slide 43

Slide 44

Slide 44

MARK & SWEEP

Slide 45

Slide 45

MARK & SWEEP

Slide 46

Slide 46

MARK & SWEEP

Slide 47

Slide 47

MARK & SWEEP

Slide 48

Slide 48

MARK & SWEEP

Slide 49

Slide 49

MARK & SWEEP

Slide 50

Slide 50

MARK & SWEEP

Slide 51

Slide 51

MARK & SWEEP

Slide 52

Slide 52

MARK & SWEEP

Slide 53

Slide 53

MARK & SWEEP

Slide 54

Slide 54

MARK & SWEEP

Slide 55

Slide 55

MARK & SWEEP

Slide 56

Slide 56

COPYING COLLECTION Keep your stuff together

Slide 57

Slide 57

COPYING COLLECTION 0 1 2 3 4 5 6 7 8

Slide 58

Slide 58

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

Slide 59

Slide 59

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

Slide 60

Slide 60

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

Slide 61

Slide 61

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

Slide 62

Slide 62

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

Slide 63

Slide 63

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

Slide 64

Slide 64

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

Slide 65

Slide 65

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

Slide 66

Slide 66

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

Slide 67

Slide 67

GENERATIONAL COLLECTION New objects Old objects D

Slide 68

Slide 68

GENERATIONAL COLLECTION New objects Old objects D

Slide 69

Slide 69

GENERATIONAL COLLECTION New objects Old objects D

Slide 70

Slide 70

GENERATIONAL COLLECTION New objects Old objects D

Slide 71

Slide 71

GENERATIONAL COLLECTION New objects Old objects D

Slide 72

Slide 72

GENERATIONAL COLLECTION New objects Old objects D

Slide 73

Slide 73

GENERATIONAL COLLECTION New objects Old objects D

Slide 74

Slide 74

GENERATIONAL COLLECTION New objects Old objects D

Slide 75

Slide 75

GENERATIONAL COLLECTION New objects Old objects D

Slide 76

Slide 76

GENERATIONAL COLLECTION New objects Old objects D

Slide 77

Slide 77

GENERATIONAL COLLECTION New objects Old objects D

Slide 78

Slide 78

GENERATIONAL COLLECTION New objects Old objects D

Slide 79

Slide 79

GENERATIONAL COLLECTION New objects Old objects D

Slide 80

Slide 80

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

Slide 81

Slide 81

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