Download presentation
Presentation is loading. Please wait.
1
List Allocation and Garbage Collection
Example
2
Memory Allocation AVAIL = 0 (0 0 0 0 0 0 0 0) Initialize Heap
1 AVAIL = 0 ( ) Initialize Heap denotes list 2 1 3 2 4 3 5 4 6 5 7 6 -1 7
3
Memory Allocation AVAIL = 0 (define L (list 1 2 3))
1 AVAIL = 0 (define L (list 1 2 3)) (cons 1 (cons 2 (cons 3 ‘()))) 2 1 3 2 4 3 5 4 6 5 7 6 -1 7
4
Memory Allocation AVAIL = 1 (define L (list 1 2 3))
-1 AVAIL = 1 (define L (list 1 2 3)) (cons 1 (cons 2 (cons 3 ‘()))) 2 1 3 2 4 3 5 4 6 5 7 6 -1 7
5
Memory Allocation AVAIL = 2 (define L (list 1 2 3))
-1 AVAIL = 2 (define L (list 1 2 3)) (cons 1 (cons 2 (cons 3 ‘()))) 2 1 3 2 4 3 5 4 6 5 7 6 -1 7
6
Memory Allocation AVAIL = 3 (0 0 0 0 0) L = 2 (1 2 3)
-1 AVAIL = 3 ( ) L = 2 (1 2 3) (define L (list 1 2 3)) (cons 1 (cons 2 (cons 3 ‘()))) 2 1 1 1 2 4 3 5 4 6 5 7 6 -1 7
7
Memory Allocation AVAIL = 5 (0 0 0), L = 2 (1 2 3), M = 4 (4 5)
-1 AVAIL = 5 (0 0 0), L = 2 (1 2 3), M = 4 (4 5) (define L (list 1 2 3)) (define M (list 4 5)) 2 1 1 1 2 5 -1 3 4 3 4 6 5 7 6 -1 7
8
Memory Allocation AVAIL = -1 NULL, L = 2 (1 2 3), M = 4 (4 5)
AVAIL = -1 NULL, L = 2 (1 2 3), M = 4 (4 5) N = 7 (6 7 8) (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) 2 1 1 1 2 5 -1 3 4 3 4 8 -1 5 7 5 6 6 6 7
9
Memory Allocation AVAIL = -1 NULL, L = 2 ((4 5) 2 3),
AVAIL = -1 NULL, L = 2 ((4 5) 2 3), M = 4 (4 5) N = 7 (6 7 8) (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M); overlap 2 1 4 1 2 5 -1 3 4 3 4 8 -1 5 7 5 6 6 6 7
10
Memory Allocation AVAIL = -1 NULL, L = 2 ((4 5) 2 3), M = 0 [int]
AVAIL = -1 NULL, L = 2 ((4 5) 2 3), M = 0 [int] N = 7 (6 7 8) (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M) (define M 0) ; cells still accessible 2 1 4 1 2 5 -1 3 4 3 4 8 -1 5 7 5 6 6 6 7
11
Memory Allocation AVAIL = -1 NULL, L = 2 ((4 5) 2 3), M = 0 [int]
AVAIL = -1 NULL, L = 2 ((4 5) 2 3), M = 0 [int] N = 0 [int] (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M) (define M 0) (define N 0) ; cells garbage 2 1 4 1 2 5 -1 3 4 3 4 8 -1 5 7 5 6 6 6 7
12
Garbage Collection AVAIL = -1 NULL, L = 2 ((4 5) 2 3), M = 0 [int]
AVAIL = -1 NULL, L = 2 ((4 5) 2 3), M = 0 [int] N = 0 [int] (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M) (define M 0) (define N 0) (define N (list 1)); AVAIL = NULL garbage collection 2 1 4 1 2 5 -1 3 4 3 4 8 -1 5 7 5 6 6 6 7
13
Mark AVAIL = -1 NULL, L = 2 ((4 5) 2 3), M = 0 [int] N = 0 [int]
AVAIL = -1 NULL, L = 2 ((4 5) 2 3), M = 0 [int] N = 0 [int] (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M) (define M 0) (define N 0) (define N (list 1)) Mark L 2 1 4 1 2 5 -1 3 4 3 4 8 -1 5 7 5 6 6 6 7
14
Mark AVAIL = -1 NULL, L = 2 ((4 5) 2 3), M = 0 [int] N = 0 [int]
AVAIL = -1 NULL, L = 2 ((4 5) 2 3), M = 0 [int] N = 0 [int] (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M) (define M 0) (define N 0) (define N (list 1)) Mark L 2 1 4 1 2 5 -1 3 4 3 4 8 -1 5 7 5 6 6 6 7
15
Mark AVAIL = -1 NULL, L = 2 ((4 5) 2 3), M = 0 [int] N = 0 [int]
AVAIL = -1 NULL, L = 2 ((4 5) 2 3), M = 0 [int] N = 0 [int] (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M) (define M 0) (define N 0) (define N (list 1)) Mark L 2 1 4 1 2 5 -1 3 4 3 4 8 -1 5 7 5 6 6 6 7
16
Mark AVAIL = -1 NULL, L = 2 ((4 5) 2 3), M = 0 [int] N = 0 [int]
AVAIL = -1 NULL, L = 2 ((4 5) 2 3), M = 0 [int] N = 0 [int] (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M) (define M 0) (define N 0) (define N (list 1)) Mark L 2 1 4 1 2 5 -1 3 4 3 4 8 -1 5 7 5 6 6 6 7
17
Mark AVAIL = -1 NULL, L = 2 ((4 5) 2 3), M = 0 [int] N = 0 [int]
AVAIL = -1 NULL, L = 2 ((4 5) 2 3), M = 0 [int] N = 0 [int] (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M) (define M 0) (define N 0) (define N (list 1)) Mark L 2 1 4 1 2 5 -1 3 4 3 4 8 -1 5 7 5 6 6 6 7
18
Sweep AVAIL = 5 (0) L = 2 ((4 5) 2 3), M = 0 [int] N = 0 [int]
-1 AVAIL = 5 (0) L = 2 ((4 5) 2 3), M = 0 [int] N = 0 [int] (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M) (define M 0) (define N 0) (define N (list 1)) Reclaim unmarked cells 2 1 4 1 2 5 -1 3 4 3 4 -1 5 7 5 6 6 6 7
19
Sweep AVAIL = 6 (0 0) L = 2 ((4 5) 2 3), M = 0 [int] N = 0 [int]
-1 AVAIL = 6 (0 0) L = 2 ((4 5) 2 3), M = 0 [int] N = 0 [int] (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M) (define M 0) (define N 0) (define N (list 1)) Reclaim unmarked cells 2 1 4 1 2 5 -1 3 4 3 4 -1 5 5 6 6 6 7
20
Sweep AVAIL = 7 (0 0 0) L = 2 ((4 5) 2 3), M = 0 [int] N = 0 [int]
-1 AVAIL = 7 (0 0 0) L = 2 ((4 5) 2 3), M = 0 [int] N = 0 [int] (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M) (define M 0) (define N 0) (define N (list 1)) Reclaim unmarked cells 2 1 4 1 2 5 -1 3 4 3 4 -1 5 5 6 6 7
21
Sweep AVAIL = 7 (0 0 0) L = 2 ((4 5) 2 3), M = 0 [int] N = 0 [int]
-1 AVAIL = 7 (0 0 0) L = 2 ((4 5) 2 3), M = 0 [int] N = 0 [int] (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M) (define M 0) (define N 0) (define N (list 1)) Unmark cells 2 1 4 1 2 5 -1 3 4 3 4 -1 5 5 6 6 7
22
Memory Allocation AVAIL = 6 (0 0) L = 2 ((4 5) 2 3), M = 0 [int]
-1 AVAIL = 6 (0 0) L = 2 ((4 5) 2 3), M = 0 [int] N = 7 (1) (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M) (define M 0) (define N 0) (define N (list 1)) 2 1 4 1 2 5 -1 3 4 3 4 -1 5 5 6 1 -1 7
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.