Recall & Review
beginner
What is garbage collection in programming?
Garbage collection is the automatic process of finding and freeing memory that a program no longer uses, so the memory can be reused.
Click to reveal answer
beginner
Why is garbage collection important?
It helps prevent memory leaks by cleaning up unused memory, which keeps programs running smoothly without running out of memory.
Click to reveal answer
intermediate
Name two common garbage collection techniques.
Two common techniques are reference counting and mark-and-sweep. Reference counting tracks how many references point to an object. Mark-and-sweep marks reachable objects and frees the rest.
Click to reveal answer
beginner
What is a memory leak?
A memory leak happens when a program keeps memory that it no longer needs, causing less memory to be available for other tasks.
Click to reveal answer
intermediate
How does mark-and-sweep garbage collection work?
It first marks all objects that can be reached from the program’s roots, then it sweeps through memory to free objects that are not marked.
Click to reveal answer
What does garbage collection do?
✗ Incorrect
Garbage collection automatically frees memory that is no longer used by the program.
Which technique tracks how many references point to an object?
✗ Incorrect
Reference counting keeps track of how many references point to each object.
What problem does garbage collection help prevent?
✗ Incorrect
Garbage collection helps prevent memory leaks by freeing unused memory.
In mark-and-sweep, what happens to objects not marked?
✗ Incorrect
Objects not marked as reachable are freed to reclaim memory.
Which of these is NOT a garbage collection technique?
✗ Incorrect
Loop unrolling is a code optimization technique, not a garbage collection method.
Explain in simple words what garbage collection is and why it matters.
Think about cleaning up your room so you have space to move.
You got /3 concepts.
Describe how the mark-and-sweep garbage collection method works step-by-step.
Imagine marking all your friends in a crowd, then removing everyone else.
You got /3 concepts.