RD22: Memory Allocation III

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/7

flashcard set

Earn XP

Description and Tags

Garbage Collection, Memory-Related Issues in C

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

8 Terms

1
New cards

What is Garbage Collection?

Garbage Collection is a form of automatic memory management that is often employed by implicit dynamic memory allocators to reclaim heap-allocated memory.

2
New cards

Why is Garbage Collection useful?

Adds convenience for the programmer and leads to fewer memory issues.

3
New cards

What’s a key note about Garbage Collection?

Knowing when a piece of dynamically-allocated memory can be freed (cleaning up unnecessary memory and not what’s being used still).

4
New cards

Example of memory as nodes:

Any heap node that is reachable from a root node is considered still in use by the process, while heap nodes that are not reachable from root nodes are considered no longer in use and eligible to be freed.

<p><span><span>Any heap node that is reachable from a root node is considered still in use by the process, while heap nodes that are not reachable from root nodes are considered no longer in use and eligible to be freed.</span></span></p>
5
New cards

What assumptions let Garbage Collection work?

  1. The memory allocator knows which data are pointers and which are not.

  2. All pointers to heap nodes point to the start of the payload.

6
New cards

What is makr-and-sweep?

An implementation of garbage collection that requires the use of an extra status bit called the mark bit.

7
New cards

What happens when the garbage collector is invoked?

  1. Recursively follows all of the root nodes into the heap and sets the mark bit for all reachable heap blocks.

  2. Sweeps through the heap forms tart to finish and check mark bit for each block.

    1. If the mark bit is set, then clear it and move on.

    2. If the mark bit is not set, then free the block as it is unused.

<ol><li><p>Recursively follows all of the root nodes into the heap and sets the mark bit for all reachable heap blocks.</p></li><li><p>Sweeps through the heap forms tart to finish and check mark bit for each block.</p><ol><li><p>If the mark bit is set, then clear it and move on.</p></li><li><p class="amber-el amber-paragraph amber-content">If the mark bit is not set, then free the block as it is unused.</p></li></ol></li></ol><p></p>
8
New cards