



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




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