This preview shows page 1. Sign up to view the full content.
Unformatted text preview: any unmarked allocated blocks (i.e., garbage) that it encounters. Figure 10.54 shows a graphical interpretation of Mark&Sweep for a small heap. Block boundaries are indicated by heavy lines. Each square corresponds to a word of memory. Each block has a one-word header, which is either marked or unmarked. Initially, the heap in Figure 10.53 consists of six allocated blocks, each of which is unmarked. Block 3 contains a pointer to block 1. Block 4 contains pointers to blocks 3 and 6. The root points to block 4. After the mark phase, blocks 1,3, 4, and 6 are marked because they are reachable from the root. Blocks 2 and 5 are unmarked because they are unreachable. After the sweep phase, the two unreachable blocks are reclaimed to the free list. 550
1 2 3 4 5 6 CHAPTER 10. VIRTUAL MEMORY Before mark: unmarked block header After mark: marked block header After sweep: free free Figure 10.54: Mark and sweep example. Note that the arrows in this example denote memory references, and not free list pointers. 10.10.3 Conservative Mark&Sweep for C Programs
Mark&Sweep is an appropriate approach for garbage collecting C programs because it works in place without...
View Full Document
This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.
- Spring '10
- The American