Jesús Espino
April 20, 2024
77

# Understanding the memory model of 5 languages

In this talk we are going to explore the memory management model for 5 different languages, C, Rust, Python, Go and Java. For each language we are going to see different ways of handling memory. We are going to explore concepts like the heap, the stack, garbage collection, mark and sweep, or stop the world. After this talk you should be able to understand most of the programming languages memory models and garbage collectors by understanding the main traits of that language.

April 20, 2024

## Transcript

1. ### JESÚS ESPINO PRINCIPAL ENGINEER @ MATTERMOST warmup Understanding the memory

model of 5 languages/ Or most of them DEVOXX FRANCE 2024

3. ### Thematic DEVELOPMENT & LANGUAGES DEVOXX FRANCE 2024 Introduction The Heap

& the Stack DEVOXX FRANCE 2024
4. ### The Heap DEVOXX FRANCE 2024 The Stack function X: local

variable a (int32) local variable b (int32) function Y: local variable c (int32) local variable d (int64) function Z: local variable e (int64) local variable f (int64) call X call Y call Z call Y
5. ### The Heap DEVOXX FRANCE 2024 The Stack function X: local

variable a (int32) local variable b (int32) function Y: local variable c (int32) local variable d (int64) function Z: local variable e (int64) local variable f (int64) call X call Y call Z call Y a = ? b = ? 8 bytes
6. ### The Heap DEVOXX FRANCE 2024 The Stack function X: local

variable a (int32) local variable b (int32) function Y: local variable c (int32) local variable d (int64) function Z: local variable e (int64) local variable f (int64) call X call Y call Z call Y a = ? b = ? 8 bytes c = ? d = ? 12 bytes
7. ### The Heap DEVOXX FRANCE 2024 The Stack function X: local

variable a (int32) local variable b (int32) function Y: local variable c (int32) local variable d (int64) function Z: local variable e (int64) local variable f (int64) call X call Y call Z call Y a = ? b = ? 8 bytes c = ? d = ? 12 bytes
8. ### The Heap DEVOXX FRANCE 2024 The Stack function X: local

variable a (int32) local variable b (int32) function Y: local variable c (int32) local variable d (int64) function Z: local variable e (int64) local variable f (int64) call X call Y call Z call Y a = ? b = ? 8 bytes e = ? f = ? 16 bytes
9. ### The Heap DEVOXX FRANCE 2024 The Stack function X: local

variable a (int32) local variable b (int32) function Y: local variable c (int32) local variable d (int64) function Z: local variable e (int64) local variable f (int64) call X call Y call Z call Y a = ? b = ? 8 bytes e = ? f = ? 16 bytes
10. ### The Heap DEVOXX FRANCE 2024 The Stack function X: local

variable a (int32) local variable b (int32) function Y: local variable c (int32) local variable d (int64) function Z: local variable e (int64) local variable f (int64) call X call Y call Z call Y c = ? d = ? 12 bytes
11. ### The Heap DEVOXX FRANCE 2024 The Stack function X: local

variable a (int32) local variable b (int32) function Y: local variable c (int32) local variable d (int64) function Z: local variable e (int64) local variable f (int64) call X call Y call Z call Y c = ? d = ? 12 bytes
12. ### The Heap DEVOXX FRANCE 2024 The Heap x = malloc(32)

free(x) y = malloc(64) z = malloc(128) free(y) free(z)
13. ### The Heap DEVOXX FRANCE 2024 The Heap x = malloc(32)

free(x) y = malloc(64) z = malloc(128) free(y) free(z)
14. ### The Heap DEVOXX FRANCE 2024 The Heap x = malloc(32)

free(x) y = malloc(64) z = malloc(128) free(y) free(z)
15. ### The Heap DEVOXX FRANCE 2024 The Heap x = malloc(32)

free(x) y = malloc(64) z = malloc(128) free(y) free(z)
16. ### The Heap DEVOXX FRANCE 2024 The Heap x = malloc(32)

free(x) y = malloc(64) z = malloc(128) free(y) free(z)
17. ### The Heap DEVOXX FRANCE 2024 The Heap x = malloc(32)

free(x) y = malloc(64) z = malloc(128) free(y) free(z)
18. ### The Heap DEVOXX FRANCE 2024 The Heap x = malloc(32)

free(x) y = malloc(64) z = malloc(128) free(y) free(z)
19. ### Introduction DEVOXX FRANCE 2024 The Stack func main() { x

:= sum(3, 5) fmt.Println(x) } func sum(x, y int) int { return x + y }
20. ### Introduction DEVOXX FRANCE 2024 The Stack func main() { x

:= sum(3, 5) fmt.Println(x) } func sum(x, y int) int { return x + y } Stack Frame (main) x = 0
21. ### Introduction DEVOXX FRANCE 2024 The Stack func main() { x

:= sum(3, 5) fmt.Println(x) } func sum(x, y int) int { return x + y } Stack Frame (main) x = 0
22. ### Introduction DEVOXX FRANCE 2024 The Stack func main() { x

:= sum(3, 5) fmt.Println(x) } func sum(x, y int) int { return x + y } Stack Frame (main) x = 0 Stack Frame (sum) x = 3 y = 5
23. ### Introduction DEVOXX FRANCE 2024 The Stack func main() { x

:= sum(3, 5) fmt.Println(x) } func sum(x, y int) int { return x + y } Stack Frame (main) x = 0 Stack Frame (sum) x = 3 y = 5
24. ### Introduction DEVOXX FRANCE 2024 The Stack func main() { x

:= sum(3, 5) fmt.Println(x) } func sum(x, y int) int { return x + y } Stack Frame (main) x = 8 Stack Frame (sum) x = 3 y = 5
25. ### Introduction DEVOXX FRANCE 2024 The Stack func main() { x

:= sum(3, 5) fmt.Println(x) } func sum(x, y int) int { return x + y } Stack Frame (main) x = 8 Stack Frame (sum) x = 3 y = 5
26. ### Introduction DEVOXX FRANCE 2024 The Stack func main() { x

:= sum(3, 5) fmt.Println(x) } func sum(x, y int) int { return x + y } Stack Frame (main) x = 8 Stack Frame (fmt.Println) x = 8 …
27. ### Introduction DEVOXX FRANCE 2024 The Stack func main() { x

:= sum(3, 5) fmt.Println(x) } func sum(x, y int) int { return x + y } Stack Frame (main) x = 8 Stack Frame (fmt.Println) x = 8 …
28. ### Introduction DEVOXX FRANCE 2024 The Stack Problem func main() {

x := sum(3, 5) fmt.Println(x) } func sum(x, y int) int { z := x + y return &z } Stack Frame (main) x = 0 Stack Frame (sum) x = 3 y = 5 z = 0
29. ### Introduction DEVOXX FRANCE 2024 The Stack Problem func main() {

x := sum(3, 5) fmt.Println(x) } func sum(x, y int) int { z := x + y return &z } Stack Frame (main) x = 0 Stack Frame (sum) x = 3 y = 5 z = 8
30. ### Introduction DEVOXX FRANCE 2024 The Stack Problem func main() {

x := sum(3, 5) fmt.Println(x) } func sum(x, y int) int { z := x + y return &z } Stack Frame (main) x = 0 Stack Frame (sum) x = 3 y = 5 z = 8
31. ### Introduction DEVOXX FRANCE 2024 The Stack Problem func main() {

x := sum(3, 5) fmt.Println(x) } func sum(x, y int) int { z := x + y return &z } Stack Frame (main) x = 0xFA3C Stack Frame (sum) x = 3 y = 5 z = 8
32. ### Introduction DEVOXX FRANCE 2024 The Stack Problem 2 func main()

{ list := []int{} for x:=0; x<rand.Intn(100); x++ { list = append(list, x) } fmt.Println(list) } Stack Frame (main) list = ???? x = 0
33. ### Introduction DEVOXX FRANCE 2024 The Heap func main() { size

:= rand.Intn(100) list := malloc(sizeof(int)*size) for x:=0; x<size; x++ { list[x] = x } fmt.Println(list) free(list) } Stack Frame (main) size = 38 list = 0 x = 0
34. ### Introduction DEVOXX FRANCE 2024 The Heap func main() { size

:= rand.Intn(100) list := malloc(sizeof(int)*size) for x:=0; x<size; x++ { list[x] = x } fmt.Println(list) free(list) } Stack Frame (main) size = 38 list = 0xF3C2 x = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
35. ### Introduction DEVOXX FRANCE 2024 The Heap func main() { size

:= rand.Intn(100) list := malloc(sizeof(int)*size) for x:=0; x<size; x++ { list[x] = x } fmt.Println(list) free(list) } Stack Frame (main) size = 38 list = 0xF3C2 x = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
36. ### Introduction DEVOXX FRANCE 2024 The Heap func main() { size

:= rand.Intn(100) list := malloc(sizeof(int)*size) for x:=0; x<size; x++ { list[x] = x } fmt.Println(list) free(list) } Stack Frame (main) size = 38 list = 0xF3C2 x = 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
37. ### Introduction DEVOXX FRANCE 2024 The Heap func main() { size

:= rand.Intn(100) list := malloc(sizeof(int)*size) for x:=0; x<size; x++ { list[x] = x } fmt.Println(list) free(list) } Stack Frame (main) size = 38 list = 0xF3C2 x = 2 0 1 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
38. ### Introduction DEVOXX FRANCE 2024 The Heap func main() { size

:= rand.Intn(100) list := malloc(sizeof(int)*size) for x:=0; x<size; x++ { list[x] = x } fmt.Println(list) free(list) } Stack Frame (main) size = 38 list = 0xF3C2 x = 38 … 38
39. ### Introduction DEVOXX FRANCE 2024 The Heap func main() { size

:= rand.Intn(100) list := malloc(sizeof(int)*size) for x:=0; x<size; x++ { list[x] = x } fmt.Println(list) free(list) } Stack Frame (main) size = 38 list = 0xF3C2 x = 38
40. ### Introduction DEVOXX FRANCE 2024 The Heap func main() { size

:= rand.Intn(100) list := malloc(sizeof(int)*size) for x:=0; x<size; x++ { list[x] = x } fmt.Println(list) free(list) } Stack Frame (main) size = 38 list = 0xF3C2 x = 38
41. ### / SUMMARY DEVOXX FRANCE 2024 summary 1. The manual model

C 2. Ownership and borrowing Rust 3. Reference counting Python 4. Mark and Sweep Go 5. Mark and Sweep (Generational) Java
42. ### Thematic DEVELOPMENT & LANGUAGES DEVOXX FRANCE 2024 The manual model

C DEVOXX FRANCE 2024
43. ### / Manual Model DEVOXX FRANCE 2024 C 1. Everything goes

to the stack 2. You manually ask for heap space 3. Use the heap for dynamic size entities 4. Use the heap for entities that survive the function call
44. ### Thematic DEVELOPMENT & LANGUAGES DEVOXX FRANCE 2024 Ownership and Borrowing

Rust DEVOXX FRANCE 2024
45. ### / Ownership and Borrowing DEVOXX FRANCE 2024 RUST 1. Basic

types goes to the stack 2. Some types use space in the heap 3. You lend or give objects to other functions 4. The owner of the function frees the heap memory on finish
46. ### RUST DEVOXX FRANCE 2024 Rust Heap and Stack fn myfunc()

{ let mut list = Vec::new(); for x in 1..6 { list.push(x); } println!("{:?}", list); } Stack Frame (myfunc) list = {len: 0, cap: 0, ptr: 0} x = 0
47. ### RUST DEVOXX FRANCE 2024 Rust Heap and Stack fn myfunc()

{ let mut list = Vec::new(); for x in 1..6 { list.push(x); } println!("{:?}", list); } Stack Frame (myfunc) list = {len: 0, cap: 0, ptr: 0} x = 1
48. ### RUST DEVOXX FRANCE 2024 Rust Heap and Stack fn myfunc()

{ let mut list = Vec::new(); for x in 1..6 { list.push(x); } println!("{:?}", list); } Stack Frame (myfunc) list = {len: 1, cap: 1, ptr: 0xFCA1} x = 1 1
49. ### RUST DEVOXX FRANCE 2024 Rust Heap and Stack fn myfunc()

{ let mut list = Vec::new(); for x in 1..6 { list.push(x); } println!("{:?}", list); } Stack Frame (myfunc) list = {len: 2, cap: 2, ptr: 0xFCBA} x = 2 1 1 2
50. ### RUST DEVOXX FRANCE 2024 Rust Heap and Stack fn myfunc()

{ let mut list = Vec::new(); for x in 1..6 { list.push(x); } println!("{:?}", list); } Stack Frame (myfunc) list = {len: 3, cap: 4, ptr: 0xFCCA} x = 3 1 2 1 2 3 0
51. ### RUST DEVOXX FRANCE 2024 Rust Heap and Stack fn myfunc()

{ let mut list = Vec::new(); for x in 1..6 { list.push(x); } println!("{:?}", list); } Stack Frame (myfunc) list = {len: 4, cap: 4, ptr: 0xFCCA} x = 4 1 2 3 4
52. ### RUST DEVOXX FRANCE 2024 Rust Heap and Stack fn myfunc()

{ let mut list = Vec::new(); for x in 1..6 { list.push(x); } println!("{:?}", list); } Stack Frame (myfunc) list = {len: 5, cap: 8, ptr: 0xFCFA} x = 5 1 2 3 0 1 2 3 4 5 0 0 0
53. ### RUST DEVOXX FRANCE 2024 Rust Heap and Stack fn myfunc()

{ let mut list = Vec::new(); for x in 1..6 { list.push(x); } println!("{:?}", list); } Stack Frame (myfunc) list = {len: 5, cap: 8, ptr: 0xFCFA} x = 6 1 2 3 4 5 6 0 0
54. ### RUST DEVOXX FRANCE 2024 Rust Heap and Stack fn myfunc()

{ let mut list = Vec::new(); for x in 1..6 { list.push(x); } println!("{:?}", list); } Stack Frame (myfunc) list = {len: 5, cap: 8, ptr: 0xFCFA} x = 6 1 2 3 4 5 6 0 0
55. ### RUST DEVOXX FRANCE 2024 Rust Heap and Stack fn myfunc()

{ let mut list = Vec::new(); for x in 1..6 { list.push(x); } println!("{:?}", list); } Stack Frame (myfunc) list = {len: 5, cap: 8, ptr: 0xFCFA} x = 6 1 2 3 4 5 6 0 0
56. ### RUST DEVOXX FRANCE 2024 Rust Heap and Stack fn myfunc()

{ let mut list = Vec::new(); for x in 1..6 { list.push(x); } otherfunc(list) // otherstuﬀ… } fn otherfunc(list: Vec<i32>) { println!("{:?}", list); } Stack Frame (myfunc) list = {len: 5, cap: 8, ptr: 0xFCFA} x = 6 1 2 3 4 5 6 0 0
57. ### RUST DEVOXX FRANCE 2024 Rust Heap and Stack fn myfunc()

{ let mut list = Vec::new(); for x in 1..6 { list.push(x); } otherfunc(list) // otherstuﬀ… } fn otherfunc(list: Vec<i32>) { println!("{:?}", list); } Stack Frame (myfunc) list = {len: 5, cap: 8, ptr: 0xFCFA} x = 6 1 2 3 4 5 6 0 0 Stack Frame (otherfunc) list = {len: 5, cap: 8, ptr: 0xFCFA}
58. ### RUST DEVOXX FRANCE 2024 Rust Heap and Stack fn myfunc()

{ let mut list = Vec::new(); for x in 1..6 { list.push(x); } otherfunc(list) // otherstuﬀ… } fn otherfunc(list: Vec<i32>) { println!("{:?}", list); } Stack Frame (myfunc) list = {len: 5, cap: 8, ptr: 0xFCFA} x = 6 1 2 3 4 5 6 0 0 Stack Frame (otherfunc) list = {len: 5, cap: 8, ptr: 0xFCFA}
59. ### RUST DEVOXX FRANCE 2024 Rust Heap and Stack fn myfunc()

{ let mut list = Vec::new(); for x in 1..6 { list.push(x); } otherfunc(list) // otherstuﬀ… } fn otherfunc(list: Vec<i32>) { println!("{:?}", list); } Stack Frame (myfunc) list = {len: 5, cap: 8, ptr: 0xFCFA} x = 6 1 2 3 4 5 6 0 0 Stack Frame (otherfunc) list = {len: 5, cap: 8, ptr: 0xFCFA}
60. ### RUST DEVOXX FRANCE 2024 Rust Heap and Stack fn myfunc()

{ let mut list = Vec::new(); for x in 1..6 { list.push(x); } otherfunc(list) // otherstuﬀ… } fn otherfunc(list: Vec<i32>) { println!("{:?}", list); } Stack Frame (myfunc) list = {len: 5, cap: 8, ptr: 0xFCFA} x = 6 1 2 3 4 5 6 0 0 Stack Frame (otherfunc) list = {len: 5, cap: 8, ptr: 0xFCFA}
61. ### RUST DEVOXX FRANCE 2024 Rust Heap and Stack fn myfunc()

{ let mut list = Vec::new(); for x in 1..6 { list.push(x); } otherfunc(&list) // otherstuﬀ… } fn otherfunc(list: &Vec<i32>) { println!("{:?}", list); } Stack Frame (myfunc) list = {len: 5, cap: 8, ptr: 0xFCFA} x = 6 1 2 3 4 5 6 0 0
62. ### RUST DEVOXX FRANCE 2024 Rust Heap and Stack fn myfunc()

{ let mut list = Vec::new(); for x in 1..6 { list.push(x); } otherfunc(&list) // otherstuﬀ… } fn otherfunc(list: &Vec<i32>) { println!("{:?}", list); } Stack Frame (myfunc) list = {len: 5, cap: 8, ptr: 0xFCFA} x = 6 1 2 3 4 5 6 0 0 Stack Frame (otherfunc) list = {len: 5, cap: 8, ptr: 0xCDA1}
63. ### RUST DEVOXX FRANCE 2024 Rust Heap and Stack fn myfunc()

{ let mut list = Vec::new(); for x in 1..6 { list.push(x); } otherfunc(&list) // otherstuﬀ… } fn otherfunc(list: &Vec<i32>) { println!("{:?}", list); } Stack Frame (myfunc) list = {len: 5, cap: 8, ptr: 0xFCFA} x = 6 1 2 3 4 5 6 0 0 Stack Frame (otherfunc) list = {len: 5, cap: 8, ptr: 0xCDA1}
64. ### RUST DEVOXX FRANCE 2024 Rust Heap and Stack fn myfunc()

{ let mut list = Vec::new(); for x in 1..6 { list.push(x); } otherfunc(&list) // otherstuﬀ… } fn otherfunc(list: &Vec<i32>) { println!("{:?}", list); } Stack Frame (myfunc) list = {len: 5, cap: 8, ptr: 0xFCFA} x = 6 1 2 3 4 5 6 0 0 Stack Frame (otherfunc) list = {len: 5, cap: 8, ptr: 0xCDA1}
65. ### RUST DEVOXX FRANCE 2024 Rust Heap and Stack fn myfunc()

{ let mut list = Vec::new(); for x in 1..6 { list.push(x); } otherfunc(&list) // otherstuﬀ… } fn otherfunc(list: &Vec<i32>) { println!("{:?}", list); } Stack Frame (myfunc) list = {len: 5, cap: 8, ptr: 0xFCFA} x = 6 1 2 3 4 5 6 0 0 Stack Frame (otherfunc) list = {len: 5, cap: 8, ptr: 0xCDA1}
66. ### RUST DEVOXX FRANCE 2024 Rust Heap and Stack fn myfunc()

{ let mut list = Vec::new(); for x in 1..6 { list.push(x); } otherfunc(&list) // otherstuﬀ… } fn otherfunc(list: &Vec<i32>) { println!("{:?}", list); } Stack Frame (myfunc) list = {len: 5, cap: 8, ptr: 0xFCFA} x = 6 1 2 3 4 5 6 0 0 Stack Frame (otherfunc) list = {len: 5, cap: 8, ptr: 0xCDA1}
67. ### Thematic DEVELOPMENT & LANGUAGES DEVOXX FRANCE 2024 Reference counting Python

DEVOXX FRANCE 2024
68. ### Python DEVOXX FRANCE 2024 Reference Counting ROOT Globals Stacks 1

rc=1 2 rc=1 6 rc=1 3 rc=1 5 rc=1 4 rc=2 7 rc=1 9 rc=1 8 rc=2
69. ### Python DEVOXX FRANCE 2024 Reference Counting ROOT Globals Stacks 1

rc=1 2 rc=1 6 rc=1 3 rc=1 5 rc=1 4 rc=2 7 rc=1 9 rc=1 8 rc=2
70. ### Python DEVOXX FRANCE 2024 Reference Counting ROOT Globals Stacks 1

rc=1 2 rc=1 6 rc=1 3 rc=1 5 rc=1 4 rc=2 7 rc=1 9 rc=0 8 rc=2
71. ### Python DEVOXX FRANCE 2024 Reference Counting ROOT Globals Stacks 1

rc=1 2 rc=1 6 rc=1 3 rc=1 5 rc=1 4 rc=2 7 rc=1 8 rc=2
72. ### Python DEVOXX FRANCE 2024 Reference Counting ROOT Globals Stacks 1

rc=1 2 rc=1 6 rc=1 3 rc=1 5 rc=1 4 rc=2 7 rc=1 8 rc=1
73. ### Python DEVOXX FRANCE 2024 Reference Counting ROOT Globals Stacks 1

rc=1 2 rc=1 6 rc=1 3 rc=1 5 rc=1 4 rc=2 7 rc=1 9 rc=1 8 rc=1
74. ### Python DEVOXX FRANCE 2024 Reference Counting ROOT Globals Stacks 1

rc=1 2 rc=1 6 rc=1 3 rc=1 5 rc=1 4 rc=2 7 rc=1 9 rc=1 8 rc=1
75. ### Python DEVOXX FRANCE 2024 Reference Counting ROOT Globals Stacks 1

rc=1 2 rc=1 6 rc=1 3 rc=1 5 rc=1 4 rc=1 7 rc=1 9 rc=1 8 rc=1
76. ### Python DEVOXX FRANCE 2024 Reference Counting ROOT Globals Stacks 1

rc=1 2 rc=1 6 rc=1 3 rc=1 5 rc=1 4 rc=1 7 rc=1 9 rc=1 8 rc=1
77. ### Python DEVOXX FRANCE 2024 Python Heap and Stack def myfunc():

size = 6 l = [] for x in range(size): l.append(x) print(l) Stack Frame (myfunc) list = 0 size = 0xAF1C x = 0 rc=1 value = 6
78. ### Python DEVOXX FRANCE 2024 Python Heap and Stack def myfunc():

size = 6 l = [] for x in range(size): l.append(x) print(l) Stack Frame (myfunc) list = 0xFC1A size = 0xAF1C x = 0 rc=1 size=0 allocated=0 data=0 rc=1 value = 6
79. ### Python DEVOXX FRANCE 2024 Python Heap and Stack def myfunc():

size = 6 l = [] for x in range(size): l.append(x) print(l) Stack Frame (myfunc) list = 0xFC1A size = 0xAF1C x = 0xFC2B rc=1 size=0 allocated=0 data=0 rc=1 value = 6 rc=1 value = 0
80. ### Python DEVOXX FRANCE 2024 Python Heap and Stack def myfunc():

size = 6 l = [] for x in range(size): l.append(x) print(l) Stack Frame (myfunc) list = 0xFC1A size = 0xAF1C x = 0xFC2B rc=1 size=1 allocated=1 data=0xFD12 rc=1 value = 6 rc=2 value = 0 0xFC2B
81. ### Python DEVOXX FRANCE 2024 Python Heap and Stack def myfunc():

size = 6 l = [] for x in range(size): l.append(x) print(l) Stack Frame (myfunc) list = 0xFC1A size = 0xAF1C x = 0xFC4B rc=1 size=1 allocated=1 data=0xFD12 rc=1 value = 6 rc=1 value = 0 0xFC2B rc=1 value = 1
82. ### Python DEVOXX FRANCE 2024 Python Heap and Stack def myfunc():

size = 6 l = [] for x in range(size): l.append(x) print(l) Stack Frame (myfunc) list = 0xFC1A size = 0xAF1C x = 0xFC4B rc=1 size=2 allocated=2 data=0xFD42 rc=1 value = 6 rc=1 value = 0 0xFC2B 0xFC4B rc=2 value = 1 0xFC2B
83. ### Python DEVOXX FRANCE 2024 Python Heap and Stack def myfunc():

size = 6 l = [] for x in range(size): l.append(x) print(l) Stack Frame (myfunc) list = 0xFC1A size = 0xAF1C x = 0xFD3A rc=1 size=8 allocated=6 data=0xFD82 rc=1 value = 6 rc=1 value = 0 0xFC2B 0xFC4B 0xFC8A 0xFCAC 0xFD1B 0xFD3A rc=1 value = 1 rc=1 value = 2 rc=1 value = 3 rc=1 value = 4 rc=1 value = 5
84. ### Python DEVOXX FRANCE 2024 Python Heap and Stack def myfunc():

size = 6 l = [] for x in range(size): l.append(x) print(l) Stack Frame (myfunc) list = 0xFC1A size = 0xAF1C x = 0xFD3A rc=0 size=8 allocated=6 data=0xFD82 rc=0 value = 6 rc=0 value = 0 0xFC2B 0xFC4B 0xFC8A 0xFCAC 0xFD1B 0xFD3A rc=0 value = 1 rc=0 value = 2 rc=0 value = 3 rc=0 value = 4 rc=0 value = 5
85. ### Python DEVOXX FRANCE 2024 Python Heap and Stack def myfunc():

x = 3 y = 4 add(x, y) def add(x, y): z = x + y return z Stack Frame (myfunc) x = 0 y = 0
86. ### Python DEVOXX FRANCE 2024 Python Heap and Stack def myfunc():

x = 3 y = 4 add(x, y) def add(x, y): z = x + y return z Stack Frame (myfunc) x = 0xFC12 y = 0 rc=1 value = 3
87. ### Python DEVOXX FRANCE 2024 Python Heap and Stack def myfunc():

x = 3 y = 4 add(x, y) def add(x, y): z = x + y return z Stack Frame (myfunc) x = 0xFC12 y = 0xFC24 rc=1 value = 3 rc=1 value = 4
88. ### Python DEVOXX FRANCE 2024 Python Heap and Stack def myfunc():

x = 3 y = 4 add(x, y) def add(x, y): z = x + y return z Stack Frame (myfunc) x = 0xFC12 y = 0xFC24 rc=1 value = 3 rc=1 value = 4
89. ### Python DEVOXX FRANCE 2024 Python Heap and Stack def myfunc():

x = 3 y = 4 add(x, y) def add(x, y): z = x + y return z Stack Frame (myfunc) x = 0xFC12 y = 0xFC24 rc=2 value = 3 rc=2 value = 4 Stack Frame (add) x = 0xFC12 y = 0xFC24 z = 0
90. ### Python DEVOXX FRANCE 2024 Python Heap and Stack def myfunc():

x = 3 y = 4 add(x, y) def add(x, y): z = x + y return z Stack Frame (myfunc) x = 0xFC12 y = 0xFC24 rc=2 value = 3 rc=2 value = 4 Stack Frame (add) x = 0xFC12 y = 0xFC24 z = 0xFC36 rc=1 value = 7
91. ### Python DEVOXX FRANCE 2024 Python Heap and Stack def myfunc():

x = 3 y = 4 add(x, y) def add(x, y): z = x + y return z Stack Frame (myfunc) x = 0xFC12 y = 0xFC24 rc=2 value = 3 rc=2 value = 4 Stack Frame (add) x = 0xFC12 y = 0xFC24 z = 0xFC36 rc=1 value = 7
92. ### Python DEVOXX FRANCE 2024 Python Heap and Stack def myfunc():

x = 3 y = 4 add(x, y) def add(x, y): z = x + y return z Stack Frame (myfunc) x = 0xFC12 y = 0xFC24 rc=2 value = 3 rc=2 value = 4 Stack Frame (add) x = 0xFC12 y = 0xFC24 z = 0xFC36 rc=1 value = 7
93. ### Python DEVOXX FRANCE 2024 Python Heap and Stack def myfunc():

x = 3 y = 4 add(x, y) def add(x, y): z = x + y return z Stack Frame (myfunc) x = 0xFC12 y = 0xFC24 rc=1 value = 3 rc=1 value = 4 Stack Frame (add) x = 0xFC12 y = 0xFC24 z = 0xFC36 rc=0 value = 7
94. ### Python DEVOXX FRANCE 2024 Python Heap and Stack def myfunc():

x = 3 y = 4 add(x, y) def add(x, y): z = x + y return z Stack Frame (myfunc) x = 0xFC12 y = 0xFC24 rc=0 value = 3 rc=0 value = 4
95. ### Thematic DEVELOPMENT & LANGUAGES DEVOXX FRANCE 2024 Mark and Sweep

Go DEVOXX FRANCE 2024
96. ### Thematic DEVELOPMENT & LANGUAGES DEVOXX FRANCE 2024 Stop the world

DEVOXX FRANCE 2024
97. ### Go DEVOXX FRANCE 2024 Go Garbage Collector ROOT Globals Stacks

1 2 6 3 5 4 7 9 8
98. ### Go DEVOXX FRANCE 2024 Go Garbage Collector ROOT Globals Stacks

1 2 6 3 5 4 7 9 8
99. ### Go DEVOXX FRANCE 2024 Go Garbage Collector ROOT Globals Stacks

1 2 6 3 5 4 7 9 8
100. ### Go DEVOXX FRANCE 2024 Go Garbage Collector ROOT Globals Stacks

1 2 6 3 5 4 7 9 8
101. ### Go DEVOXX FRANCE 2024 Go Garbage Collector ROOT Globals Stacks

1 2 6 3 5 4 7 9 8
102. ### Go DEVOXX FRANCE 2024 Go Garbage Collector ROOT Globals Stacks

1 2 6 3 5 4 7 9 8
103. ### Go DEVOXX FRANCE 2024 Go Garbage Collector ROOT Globals Stacks

1 2 6 3 5 4 7 9 8
104. ### Go DEVOXX FRANCE 2024 Go Garbage Collector ROOT Globals Stacks

1 2 6 3 5 4 7 9 8
105. ### Go DEVOXX FRANCE 2024 Go Garbage Collector ROOT Globals Stacks

1 2 6 3 5 4 7 9 8
106. ### Go DEVOXX FRANCE 2024 Go Heap and Stack func myfunc()

{ size := rand.Intn(100) list := []int{} for x:=0; x<size; x++ { list = append(list, x) } fmt.Println(list) } func main() { myfunc() } Stack Frame (main)
107. ### Go DEVOXX FRANCE 2024 Go Heap and Stack func myfunc()

{ size := rand.Intn(100) list := []int{} for x:=0; x<size; x++ { list = append(list, x) } fmt.Println(list) } func main() { myfunc() } Stack Frame (main) Stack Frame (myfunc) size = 6 x = 0 list = nil
108. ### Go DEVOXX FRANCE 2024 Go Heap and Stack func myfunc()

{ size := rand.Intn(100) list := []int{} for x:=0; x<size; x++ { list = append(list, x) } fmt.Println(list) } func main() { myfunc() } Stack Frame (myfunc) size = 6 x = 0 list = {len: 0, cap: 0, data: 0} Stack Frame (main)
109. ### Go DEVOXX FRANCE 2024 Go Heap and Stack func myfunc()

{ size := rand.Intn(100) list := []int{} for x:=0; x<size; x++ { list = append(list, x) } fmt.Println(list) } func main() { myfunc() } Stack Frame (myfunc) size = 6 x = 0 list = {len: 1, cap: 1, data: 0xFC1A} 0 Stack Frame (main)
110. ### Go DEVOXX FRANCE 2024 Go Heap and Stack func myfunc()

{ size := rand.Intn(100) list := []int{} for x:=0; x<size; x++ { list = append(list, x) } fmt.Println(list) } func main() { myfunc() } Stack Frame (myfunc) size = 6 x = 0 list = {len: 1, cap: 1, data: 0xFC2A} 0 Stack Frame (main) 0 1
111. ### Go DEVOXX FRANCE 2024 Go Heap and Stack func myfunc()

{ size := rand.Intn(100) list := []int{} for x:=0; x<size; x++ { list = append(list, x) } fmt.Println(list) } func main() { myfunc() } Stack Frame (myfunc) size = 6 x = 0 list = {len: 1, cap: 1, data: 0xFC4A} 0 Stack Frame (main) 0 1 0 1 3 0
112. ### Go DEVOXX FRANCE 2024 Go Heap and Stack func myfunc()

{ size := rand.Intn(100) list := []int{} for x:=0; x<size; x++ { list = append(list, x) } fmt.Println(list) } func main() { myfunc() } Stack Frame (myfunc) size = 6 x = 0 list = {len: 1, cap: 1, data: 0xFC4A} 0 Stack Frame (main) 0 1 0 1 3 4
113. ### Go DEVOXX FRANCE 2024 Go Heap and Stack func myfunc()

{ size := rand.Intn(100) list := []int{} for x:=0; x<size; x++ { list = append(list, x) } fmt.Println(list) } func main() { myfunc() } Stack Frame (myfunc) size = 6 x = 0 list = {len: 1, cap: 1, data: 0xFC8A} 0 Stack Frame (main) 0 1 0 1 3 4 0 1 3 4 5 0 0 0
114. ### Go DEVOXX FRANCE 2024 Go Heap and Stack func myfunc()

{ size := rand.Intn(100) list := []int{} for x:=0; x<size; x++ { list = append(list, x) } fmt.Println(list) } func main() { myfunc() } Stack Frame (myfunc) size = 6 x = 0 list = {len: 1, cap: 1, data: 0xFC8A} 0 Stack Frame (main) 0 1 0 1 3 4 0 1 3 4 5 0 0 0 GC
115. ### Go DEVOXX FRANCE 2024 Go Heap and Stack func myfunc()

{ size := rand.Intn(100) list := []int{} for x:=0; x<size; x++ { list = append(list, x) } fmt.Println(list) } func main() { myfunc() } Stack Frame (myfunc) size = 6 x = 0 list = {len: 1, cap: 1, data: 0xFC8A} 0 Stack Frame (main) 0 1 0 1 3 4 0 1 3 4 5 0 0 0 GC
116. ### Go DEVOXX FRANCE 2024 Go Heap and Stack func myfunc()

{ size := rand.Intn(100) list := []int{} for x:=0; x<size; x++ { list = append(list, x) } fmt.Println(list) } func main() { myfunc() } Stack Frame (myfunc) size = 6 x = 0 list = {len: 1, cap: 1, data: 0xFC8A} 0 Stack Frame (main) 0 1 0 1 3 4 0 1 3 4 5 0 0 0 GC
117. ### Go DEVOXX FRANCE 2024 Go Heap and Stack func myfunc()

{ size := rand.Intn(100) list := []int{} for x:=0; x<size; x++ { list = append(list, x) } fmt.Println(list) } func main() { myfunc() } Stack Frame (myfunc) size = 6 x = 0 list = {len: 1, cap: 1, data: 0xFC8A} 0 Stack Frame (main) 0 1 0 1 3 4 0 1 3 4 5 0 0 0 GC
118. ### Go DEVOXX FRANCE 2024 Go Heap and Stack func myfunc()

{ size := rand.Intn(100) list := []int{} for x:=0; x<size; x++ { list = append(list, x) } fmt.Println(list) } func main() { myfunc() } Stack Frame (myfunc) size = 6 x = 0 list = {len: 1, cap: 1, data: 0xFC8A} 0 Stack Frame (main) 0 1 0 1 3 4 0 1 3 4 5 0 0 0 GC
119. ### Go DEVOXX FRANCE 2024 Go Heap and Stack func myfunc()

{ size := rand.Intn(100) list := []int{} for x:=0; x<size; x++ { list = append(list, x) } fmt.Println(list) } func main() { myfunc() } Stack Frame (myfunc) size = 6 x = 0 list = {len: 1, cap: 1, data: 0xFC8A} Stack Frame (main) 0 1 3 4 5 6 0 0
120. ### Go DEVOXX FRANCE 2024 Go Heap and Stack func myfunc()

{ size := rand.Intn(100) list := []int{} for x:=0; x<size; x++ { list = append(list, x) } fmt.Println(list) } func main() { myfunc() } Stack Frame (myfunc) size = 6 x = 0 list = {len: 1, cap: 1, data: 0xFC8A} Stack Frame (main) 0 1 3 4 5 6 0 0
121. ### Go DEVOXX FRANCE 2024 Go Heap and Stack func myfunc()

{ size := rand.Intn(100) list := []int{} for x:=0; x<size; x++ { list = append(list, x) } fmt.Println(list) } func main() { myfunc() } Stack Frame (myfunc) size = 6 x = 0 list = {len: 1, cap: 1, data: 0xFC8A} Stack Frame (main) 0 1 3 4 5 6 0 0
122. ### Go DEVOXX FRANCE 2024 Go Heap and Stack func myfunc()

{ size := rand.Intn(100) list := []int{} for x:=0; x<size; x++ { list = append(list, x) } fmt.Println(list) } func main() { myfunc() } Stack Frame (main) 0 1 3 4 5 6 0 0 GC
123. ### Go DEVOXX FRANCE 2024 Go Heap and Stack func myfunc()

{ size := rand.Intn(100) list := []int{} for x:=0; x<size; x++ { list = append(list, x) } fmt.Println(list) } func main() { myfunc() } Stack Frame (main) 0 1 3 4 5 6 0 0 GC
124. ### Go DEVOXX FRANCE 2024 Go Heap and Stack func myfunc()

{ size := rand.Intn(100) list := []int{} for x:=0; x<size; x++ { list = append(list, x) } fmt.Println(list) } func main() { myfunc() } Stack Frame (main) 0 1 3 4 5 6 0 0 GC
125. ### Thematic DEVELOPMENT & LANGUAGES DEVOXX FRANCE 2024 Mark and Sweep

(Generational) Java DEVOXX FRANCE 2024
126. ### Java DEVOXX FRANCE 2024 Java GC Generations Eden Survivor zero

Survivor one Ternured ROOT Young Old
127. ### Java DEVOXX FRANCE 2024 Java GC Generations Eden Survivor zero

Survivor one Ternured GC ROOT Young Old
128. ### Java DEVOXX FRANCE 2024 Java GC Generations Eden Survivor zero

Survivor one Ternured ROOT Young Old
129. ### Java DEVOXX FRANCE 2024 Java GC Generations Eden Survivor zero

Survivor one Ternured GC ROOT Young Old
130. ### Java DEVOXX FRANCE 2024 Java GC Generations Eden Survivor zero

Survivor one Ternured ROOT Young Old
131. ### Java DEVOXX FRANCE 2024 Java GC Generations Eden Survivor zero

Survivor one Ternured GC ROOT Young Old
132. ### / OTHER LANGUAGES DEVOXX FRANCE 2024 other languages 1. C++

2. C# (.NET) 3. Erlang 4. Fortran 5. Javascript 6. Java (JVM) 7. Julia 8. LUA 9. Pascal 10. PHP 11. Perl 12. R 13. Ruby 14. Swift
133. ### DEVOXX FRANCE 2024 other languages 1. C++ 2. C# (.NET)

3. Erlang 4. Fortran 5. Javascript 6. Java (JVM) 7. Julia 8. LUA 9. Pascal 10. PHP 11. Perl 12. R 13. Ruby 14. Swift
134. ### DEVOXX FRANCE 2024 other languages 1. C++: Manual, and ownership

or refcounting with smart pointers 2. C# (.NET) 3. Erlang 4. Fortran 5. Javascript 6. Java (JVM) 7. Julia 8. LUA 9. Pascal 10. PHP 11. Perl 12. R 13. Ruby 14. Swift
135. ### DEVOXX FRANCE 2024 other languages 1. C++: Manual, and ownership

or refcounting with smart pointers 2. C# (.NET): Mark and Sweep generational 3. Erlang 4. Fortran 5. Javascript 6. Java (JVM) 7. Julia 8. LUA 9. Pascal 10. PHP 11. Perl 12. R 13. Ruby 14. Swift
136. ### DEVOXX FRANCE 2024 other languages 1. C++: Manual, and ownership

or refcounting with smart pointers 2. C# (.NET): Mark and Sweep generational 3. Erlang: Mark and Sweep generational + ref counting for shared heap 4. Fortran 5. Javascript 6. Java (JVM) 7. Julia 8. LUA 9. Pascal 10. PHP 11. Perl 12. R 13. Ruby 14. Swift
137. ### DEVOXX FRANCE 2024 other languages 1. C++: Manual, and ownership

or refcounting with smart pointers 2. C# (.NET): Mark and Sweep generational 3. Erlang: Mark and Sweep generational + ref counting for shared heap 4. Fortran: Manual 5. Javascript 6. Java (JVM) 7. Julia 8. LUA 9. Pascal 10. PHP 11. Perl 12. R 13. Ruby 14. Swift
138. ### DEVOXX FRANCE 2024 other languages 1. C++: Manual, and ownership

or refcounting with smart pointers 2. C# (.NET): Mark and Sweep generational 3. Erlang: Mark and Sweep generational + ref counting for shared heap 4. Fortran: Manual 5. Javascript: Mark and Sweep generational 6. Java (JVM) 7. Julia 8. LUA 9. Pascal 10. PHP 11. Perl 12. R 13. Ruby 14. Swift
139. ### DEVOXX FRANCE 2024 other languages 1. C++: Manual, and ownership

or refcounting with smart pointers 2. C# (.NET): Mark and Sweep generational 3. Erlang: Mark and Sweep generational + ref counting for shared heap 4. Fortran: Manual 5. Javascript: Mark and Sweep generational 6. Java (JVM): Mark and Sweep generational 7. Julia 8. LUA 9. Pascal 10. PHP 11. Perl 12. R 13. Ruby 14. Swift
140. ### DEVOXX FRANCE 2024 other languages 1. C++: Manual, and ownership

or refcounting with smart pointers 2. C# (.NET): Mark and Sweep generational 3. Erlang: Mark and Sweep generational + ref counting for shared heap 4. Fortran: Manual 5. Javascript: Mark and Sweep generational 6. Java (JVM): Mark and Sweep generational 7. Julia: Mark and Sweep generational 8. LUA 9. Pascal 10. PHP 11. Perl 12. R 13. Ruby 14. Swift
141. ### DEVOXX FRANCE 2024 other languages 1. C++: Manual, and ownership

or refcounting with smart pointers 2. C# (.NET): Mark and Sweep generational 3. Erlang: Mark and Sweep generational + ref counting for shared heap 4. Fortran: Manual 5. Javascript: Mark and Sweep generational 6. Java (JVM): Mark and Sweep generational 7. Julia: Mark and Sweep generational 8. LUA: Mark and Sweep generational (since 5.4) 9. Pascal 10. PHP 11. Perl 12. R 13. Ruby 14. Swift
142. ### DEVOXX FRANCE 2024 other languages 1. C++: Manual, and ownership

or refcounting with smart pointers 2. C# (.NET): Mark and Sweep generational 3. Erlang: Mark and Sweep generational + ref counting for shared heap 4. Fortran: Manual 5. Javascript: Mark and Sweep generational 6. Java (JVM): Mark and Sweep generational 7. Julia: Mark and Sweep generational 8. LUA: Mark and Sweep generational (since 5.4) 9. Pascal: Manual 10. PHP 11. Perl 12. R 13. Ruby 14. Swift
143. ### DEVOXX FRANCE 2024 other languages 1. C++: Manual, and ownership

or refcounting with smart pointers 2. C# (.NET): Mark and Sweep generational 3. Erlang: Mark and Sweep generational + ref counting for shared heap 4. Fortran: Manual 5. Javascript: Mark and Sweep generational 6. Java (JVM): Mark and Sweep generational 7. Julia: Mark and Sweep generational 8. LUA: Mark and Sweep generational (since 5.4) 9. Pascal: Manual 10. PHP: Reference counting 11. Perl 12. R 13. Ruby 14. Swift
144. ### DEVOXX FRANCE 2024 other languages 1. C++: Manual, and ownership

or refcounting with smart pointers 2. C# (.NET): Mark and Sweep generational 3. Erlang: Mark and Sweep generational + ref counting for shared heap 4. Fortran: Manual 5. Javascript: Mark and Sweep generational 6. Java (JVM): Mark and Sweep generational 7. Julia: Mark and Sweep generational 8. LUA: Mark and Sweep generational (since 5.4) 9. Pascal: Manual 10. PHP: Reference counting 11. Perl: Reference counting, but Raku Mark and Sweep generational 12. R 13. Ruby 14. Swift
145. ### DEVOXX FRANCE 2024 other languages 1. C++: Manual, and ownership

or refcounting with smart pointers 2. C# (.NET): Mark and Sweep generational 3. Erlang: Mark and Sweep generational + ref counting for shared heap 4. Fortran: Manual 5. Javascript: Mark and Sweep generational 6. Java (JVM): Mark and Sweep generational 7. Julia: Mark and Sweep generational 8. LUA: Mark and Sweep generational (since 5.4) 9. Pascal: Manual 10. PHP: Reference counting 11. Perl: Reference counting, but Raku Mark and Sweep generational 12. R: Mark and Sweep generational 13. Ruby 14. Swift
146. ### DEVOXX FRANCE 2024 other languages 1. C++: Manual, and ownership

or refcounting with smart pointers 2. C# (.NET): Mark and Sweep generational 3. Erlang: Mark and Sweep generational + ref counting for shared heap 4. Fortran: Manual 5. Javascript: Mark and Sweep generational 6. Java (JVM): Mark and Sweep generational 7. Julia: Mark and Sweep generational 8. LUA: Mark and Sweep generational (since 5.4) 9. Pascal: Manual 10. PHP: Reference counting 11. Perl: Reference counting, but Raku Mark and Sweep generational 12. R: Mark and Sweep generational 13. Ruby: Mark and Sweep generational 14. Swift
147. ### DEVOXX FRANCE 2024 other languages 1. C++: Manual, and ownership

or refcounting with smart pointers 2. C# (.NET): Mark and Sweep generational 3. Erlang: Mark and Sweep generational + ref counting for shared heap 4. Fortran: Manual 5. Javascript: Mark and Sweep generational 6. Java (JVM): Mark and Sweep generational 7. Julia: Mark and Sweep generational 8. LUA: Mark and Sweep generational (since 5.4) 9. Pascal: Manual 10. PHP: Reference counting 11. Perl: Reference counting, but Raku Mark and Sweep generational 12. R: Mark and Sweep generational 13. Ruby: Mark and Sweep generational 14. Swift: Reference counting