Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Understanding the memory model of 5 languages

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.

Jesús Espino

April 20, 2024
Tweet

More Decks by Jesús Espino

Other Decks in Programming

Transcript

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

    model of 5 languages/ Or most of them DEVOXX FRANCE 2024
  2. 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
  3. 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
  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 a = ? b = ? 8 bytes c = ? d = ? 12 bytes
  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 c = ? d = ? 12 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 e = ? f = ? 16 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 e = ? f = ? 16 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 c = ? d = ? 12 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 c = ? d = ? 12 bytes
  10. The Heap DEVOXX FRANCE 2024 The Heap x = malloc(32)

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

    free(x) y = malloc(64) z = malloc(128) free(y) free(z)
  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. Introduction DEVOXX FRANCE 2024 The Stack func main() { x

    := sum(3, 5) fmt.Println(x) } func sum(x, y int) int { return x + y }
  18. 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
  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 } Stack Frame (main) x = 0
  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 Stack Frame (sum) x = 3 y = 5
  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 Stack Frame (sum) x = 3 y = 5
  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 = 8 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 = 8 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 (fmt.Println) x = 8 …
  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 (fmt.Println) x = 8 …
  26. 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
  27. 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
  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 = 8
  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 = 0xFA3C Stack Frame (sum) x = 3 y = 5 z = 8
  30. 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
  31. 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
  32. 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
  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 = 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
  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 = 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
  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 = 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
  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 = 38 … 38
  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 = 38
  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
  39. / 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
  40. / 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
  41. / 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
  42. 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
  43. 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
  44. 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
  45. 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
  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: 3, cap: 4, ptr: 0xFCCA} x = 3 1 2 1 2 3 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: 4, cap: 4, ptr: 0xFCCA} x = 4 1 2 3 4
  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: 5, cap: 8, ptr: 0xFCFA} x = 5 1 2 3 0 1 2 3 4 5 0 0 0
  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: 5, cap: 8, ptr: 0xFCFA} x = 6 1 2 3 4 5 6 0 0
  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: 5, cap: 8, ptr: 0xFCFA} x = 6 1 2 3 4 5 6 0 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: 5, cap: 8, ptr: 0xFCFA} x = 6 1 2 3 4 5 6 0 0
  52. 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) // otherstuff… } 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
  53. 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) // otherstuff… } 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}
  54. 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) // otherstuff… } 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}
  55. 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) // otherstuff… } 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}
  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) // otherstuff… } 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}
  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) // otherstuff… } 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
  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) // otherstuff… } 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}
  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) // otherstuff… } 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}
  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) // otherstuff… } 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}
  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) // otherstuff… } 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}
  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) // otherstuff… } 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. 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
  64. 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
  65. 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
  66. 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
  67. 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
  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=1
  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=1
  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=1 7 rc=1 9 rc=1 8 rc=1
  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=1 7 rc=1 9 rc=1 8 rc=1
  72. 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
  73. 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
  74. 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
  75. 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
  76. 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
  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 = 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
  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 = 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
  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 = 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
  80. 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
  81. 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
  82. 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
  83. 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
  84. 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
  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 = 0xFC12 y = 0xFC24 rc=2 value = 3 rc=2 value = 4 Stack Frame (add) x = 0xFC12 y = 0xFC24 z = 0xFC36 rc=1 value = 7
  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 = 0xFC24 rc=2 value = 3 rc=2 value = 4 Stack Frame (add) x = 0xFC12 y = 0xFC24 z = 0xFC36 rc=1 value = 7
  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=2 value = 3 rc=2 value = 4 Stack Frame (add) x = 0xFC12 y = 0xFC24 z = 0xFC36 rc=1 value = 7
  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 Stack Frame (add) x = 0xFC12 y = 0xFC24 z = 0xFC36 rc=0 value = 7
  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=0 value = 3 rc=0 value = 4
  90. 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)
  91. 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
  92. 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)
  93. 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)
  94. 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
  95. 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
  96. 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
  97. 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
  98. 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
  99. 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
  100. 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
  101. 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
  102. 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
  103. 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
  104. 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
  105. 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
  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) 0 1 3 4 5 6 0 0 GC
  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) 0 1 3 4 5 6 0 0 GC
  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 (main) 0 1 3 4 5 6 0 0 GC
  109. Java DEVOXX FRANCE 2024 Java GC Generations Eden Survivor zero

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

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

    Survivor one Ternured GC ROOT Young Old
  112. / 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
  113. 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
  114. 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
  115. 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
  116. 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
  117. 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
  118. 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
  119. 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
  120. 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
  121. 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
  122. 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
  123. 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
  124. 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
  125. 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
  126. 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
  127. 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