Docsity

Garbage Collection Process in C#, Exams of Water and Wastewater Engineering

Toggle sidebar
bg1
Garbage Collection Process
2024-2025. Questions &
Correct Verified Answers.
Graded A+
How can memory leaks occur in a garbage-collected
environment like C#? A) By not allocating enough memory B)
By using too many global variables C) By maintaining references
to objects that are no longer needed D) By running garbage
collection too frequently - ANSC How does the garbage
collector determine the starting point for identifying reachable
objects in the heap? A) By scanning the entire memory B) By
checking static and local variables, CPU registers, and GC
handles C) By using a reference counting mechanism D) By
explicitly marking objects in the code - ANSB How does the
garbage collector determine which objects in the heap are no
longer in use? A) By checking the stack for references B) By
using a reference counting mechanism C) By using roots to
identify reachable objects D) By scanning the entire memory -
ANSC How does the garbage collector in C# determine if an
object is no longer needed? A) By checking the stack for
references B) By using a reference counting mechanism C) By
traversing from roots and marking reachable objects D) By
scanning the entire memory - ANSC In C#, what is a common
pf3
pf4
pf5

Partial preview of the text

Download Garbage Collection Process in C# and more Exams Water and Wastewater Engineering in PDF only on Docsity!

Garbage Collection Process

2024-2025. Questions &

Correct Verified Answers.

Graded A+

How can memory leaks occur in a garbage-collected environment like C#? A) By not allocating enough memory B) By using too many global variables C) By maintaining references to objects that are no longer needed D) By running garbage collection too frequently - ANSC How does the garbage collector determine the starting point for identifying reachable objects in the heap? A) By scanning the entire memory B) By checking static and local variables, CPU registers, and GC handles C) By using a reference counting mechanism D) By explicitly marking objects in the code - ANSB How does the garbage collector determine which objects in the heap are no longer in use? A) By checking the stack for references B) By using a reference counting mechanism C) By using roots to identify reachable objects D) By scanning the entire memory - ANSC How does the garbage collector in C# determine if an object is no longer needed? A) By checking the stack for references B) By using a reference counting mechanism C) By traversing from roots and marking reachable objects D) By scanning the entire memory - ANSC In C#, what is a common

method used to explicitly request garbage collection? A) Memory.Clear() B) System.Collect() C) GC.Collect() D) Heap.Collect() - ANSC In which generation are long-lived objects typically stored? A) Generation 0 B) Generation 1 C) Generation 2 D) Generation 3 - ANSC What does the "sweep" phase of garbage collection do? A) Marks reachable objects B) Frees memory occupied by unreachable objects C) Allocates memory for new objects D) Compacts memory - ANSB What does the GC.SuppressFinalize() method do? A) Prevents an object from being garbage collected B) Requests garbage collection for an object C) Prevents the finalizer of an object from being called D) Forces the finalizer of an object to run immediately - ANSC What does the GC.WaitForPendingFinalizers method do? A) Forces garbage collection to run immediately B) Prevents finalizers from running C) Blocks the current thread until the finalizers have been called D) Releases all unmanaged resources - ANSC What happens during a full garbage collection? A) Objects from all generations are collected B) Only Generation 0 objects are collected C) Only Generation 1 objects are collected D) Objects are never compacted - ANSA What happens to an object in the heap when it is no longer referenced? A) It becomes eligible for garbage collection B) It is immediately deallocated C) It remains in the heap indefinitely D) It is moved to the stack - ANSA What

primary goal of heap compaction during garbage collection? A) To increase the size of the heap B) To reduce fragmentation and consolidate free memory space C) To sort objects based on their type D) To move objects from the stack to the heap - ANSB What is the primary purpose of the garbage collector in relation to the heap? A) To allocate memory B) To handle exceptions C) To free memory occupied by objects that are no longer in use D) To manage CPU registers - ANSC What is the purpose of the "compacting" phase in garbage collection? A) To allocate memory B) To reduce fragmentation and consolidate free memory space C) To identify unreachable objects D) To move objects from the stack to the heap - ANSB What is the purpose of the "compacting" phase in garbage collection? A) To allocate memory B) To reduce fragmentation and consolidate free space C) To identify unreachable objects D) To move objects from the heap to the stack - ANSB What is the role of finalizers in garbage collection? A) To allocate memory for objects B) To release unmanaged resources before an object is collected C) To mark objects for garbage collection D) To prevent objects from being collected - ANSB What is the term used for memory that is dynamically allocated during the execution of a program in C#? A) Static memory B) Stack memory C) Heap memory D) Register memory - ANSC What triggers the garbage collector to run? A) A specific method call

by the programmer B) Memory allocation exceeds a certain threshold C) A fixed time interval D) Completion of every method execution - ANSB When an object is created using the new keyword in C#, where is it allocated? A) On the stack B) In the global memory space C) On the heap D) In the CPU register

  • ANSC Which generation in the heap is collected most frequently? A) Generation 0 B) Generation 1 C) Generation 2 D) Generation 3 - ANSA Which generation in the heap is intended to contain short-lived objects? A) Generation 0 B) Generation 1 C) Generation 2 D) Generation 3 - ANSA Which method can be used to manually trigger garbage collection in C#? A) Memory.Clear() B) GC.Collect() C) System.GarbageCollect() D) Heap.Collect() - ANSB Which of the following best describes the heap in C#? A) A stack of method calls B) A dynamic memory allocation area C) A fixed-size memory allocation area D) An area for static variablesB - ANSB Which of the following is NOT a root used by the garbage collector? A) Global variables B) Local variables C) CPU registers D) Private fields of objects - ANSD Which of the following is NOT a valid trigger for garbage collection in C#? A) Memory pressure B) Explicit call to GC.Collect() C) Allocation of a large object D) Fixed time interval
  • ANSD Which of the following objects are stored in the heap? A) Local variables B) Static variables C) Dynamically allocated objects D) Method parameters - ANSC Which of the following