0
0
Compiler Designknowledge~5 mins

Garbage collection basics in Compiler Design - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AAutomatically frees unused memory
BCompiles code faster
CIncreases program size
DDeletes program files
Which technique tracks how many references point to an object?
AMark-and-sweep
BReference counting
CCompaction
DStack allocation
What problem does garbage collection help prevent?
ASyntax errors
BSlow internet
CMemory leaks
DFile corruption
In mark-and-sweep, what happens to objects not marked?
AThey are kept in memory
BThey are renamed
CThey are copied
DThey are freed
Which of these is NOT a garbage collection technique?
ALoop unrolling
BMark-and-sweep
CReference counting
DCompaction
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.