Garbage Collection in Compilers MCQs December 19, 2025December 14, 2024 by u930973931_answers 30 min Score: 0 Attempted: 0/30 Subscribe 1. What is the primary purpose of garbage collection in compilers? (A) To optimize CPU instructions (B) To automatically reclaim memory that is no longer in use (C) To detect syntax errors (D) To schedule tasks for parallel execution 2. Which of the following programming languages relies heavily on garbage collection? (A) C (B) C++ (C) Java (D) Assembly 3. Which type of garbage collection identifies unreachable objects by tracing references from root objects? (A) Tracing garbage collection (B) Reference counting (C) Manual memory management (D) Stack allocation 4. What is a ârootâ in garbage collection terminology? (A) The first allocated object (B) A pointer to freed memory (C) The global memory pool (D) A variable or object directly accessible by the program and used as a starting point for tracing 5. Which garbage collection technique counts the number of references to each object? (A) Tracing collection (B) Generational collection (C) Mark-and-sweep (D) Reference counting 6. What is a major drawback of reference counting? (A) It is slow for small programs (B) It cannot reclaim cyclic data structures (C) It requires manual intervention (D) It does not work with arrays 7. What are âgarbageâ objects? (A) Objects that are frequently accessed (B) Objects stored in registers (C) Objects in the heap that are locked (D) Objects that are no longer reachable or needed by the program 8. In mark-and-sweep garbage collection, what does the âmarkâ phase do? (A) Reclaims memory immediately (B) Optimizes object allocation (C) Deletes unused variables (D) Traverses reachable objects and marks them as alive 9. In mark-and-sweep, what happens in the âsweepâ phase? (A) Allocates new memory (B) Frees memory of unmarked (unreachable) objects (C) Counts references (D) Compacts memory 10. What is generational garbage collection? (A) Dividing objects into generations based on age and collecting younger objects more frequently (B) Collecting objects in chronological order (C) Manual memory management for each object (D) Collecting all objects at once 11. Which of the following is an advantage of generational garbage collection? (A) Frequent collection of long-lived objects (B) Reduces pause times by collecting young objects often (C) Simplifies programming syntax (D) Eliminates need for memory allocation 12. What is a âstop-the-worldâ event in garbage collection? (A) When only one object is collected (B) When the program continues while collecting memory (C) When the program halts completely during garbage collection (D) When memory allocation fails 13. What is a major disadvantage of stop-the-world garbage collection? (A) It increases memory usage (B) It is slower than manual memory management (C) It causes program pauses, affecting responsiveness (D) It prevents cyclic references 14. What is incremental garbage collection? (A) Collecting garbage only at program exit (B) Manually freeing objects (C) Allocating memory incrementally (D) Breaking the collection process into small steps to reduce pause times 15. What does âcompacting garbage collectionâ do? (A) Moves live objects together to reduce memory fragmentation (B) Frees all objects at once (C) Counts references for each object (D) Marks objects as unreachable 16. What is a âmemory leakâ? (A) An object allocated multiple times (B) Memory stored in registers (C) Memory that is no longer used but cannot be reclaimed (D) Unused stack variables 17. Which of the following is a sign of memory leak in a program? (A) Frequent CPU spikes (B) Immediate program crash (C) Constant increase in heap memory usage over time (D) Frequent context switching 18. What is weak reference in garbage collection? (A) A reference that prevents an object from being collected (B) A reference that does not prevent its object from being garbage collected (C) A pointer to freed memory (D) A special type of strong reference 19. In reference counting, what is a cyclic reference problem? (A) References are lost in recursion (B) The heap overflows (C) Objects reference each other, creating a cycle, preventing collection (D) Objects are collected too frequently 20. Which garbage collection algorithm is most suitable for real-time systems? (A) Stop-the-world mark-and-sweep (B) Manual memory management (C) Reference counting only (D) Incremental or concurrent garbage collection 21. What is the role of a âfinalizerâ in garbage collection? (A) To allocate memory (B) To perform cleanup operations before an object is reclaimed (C) To mark objects as live (D) To compact memory 22. Which type of garbage collection runs concurrently with the application? (A) Stop-the-world (B) Tracing without roots (C) Manual memory management (D) Concurrent garbage collection 23. Which of the following is an advantage of automated garbage collection over manual memory management? (A) Better control over exact memory release (B) Reduced programmer errors like dangling pointers and memory leaks (C) Lower memory usage (D) Faster execution always 24. What is a âdangling pointerâ? (A) A pointer pointing to freed memory (B) A pointer pointing to a global variable (C) A pointer not assigned yet (D) A pointer used for function calls 25. What is the âstop-and-copyâ garbage collection method? (A) Counts references for all objects (B) Marks and deletes objects individually (C) Copies objects to a new memory area, reclaiming old memory in bulk (D) Only frees stack variables 26. What is âautomatic memory managementâ? (A) Manual allocation and deallocation (B) Using stack variables only (C) Garbage collection managed by the compiler/runtime without explicit programmer intervention (D) Optimizing instruction scheduling 27. Which of the following languages typically requires manual memory management? (A) Java (B) Python (C) C (D) C# 28. What is the main difference between tracing and reference counting garbage collection? (A) Tracing requires explicit programmer calls (B) Reference counting works only for arrays (C) Tracing follows object references to identify live objects, while reference counting tracks the number of references (D) Tracing cannot handle cyclic references 29. Which of the following reduces the frequency of garbage collection? (A) Allocating many short-lived objects in generational GC (B) Using smaller heaps (C) Avoiding object allocation (D) Manual memory deallocation 30. What is a key challenge in garbage collection for multi-threaded applications? (A) Scheduling threads efficiently (B) Avoiding race conditions and synchronization overhead during memory reclamation (C) Allocating large arrays (D) Compiling instructions sequentially