Microsoft Certified Solutions Developer (MCSD) Certification Practice Test

Disable ads (and more) with a membership for a one time $2.99 payment

Prepare for the Microsoft Certified Solutions Developer (MCSD) Exam with comprehensive quizzes, flashcards, and multiple-choice questions. Each query includes hints and clear explanations to help you succeed. Get exam-ready today!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


What command is used to manually invoke the garbage collector?

  1. GC.Call();

  2. GC.Clear();

  3. GC.Collect();

  4. GC.Run();

The correct answer is: GC.Collect();

The command used to manually invoke the garbage collector in .NET is GC.Collect(). This method is part of the System namespace and its primary purpose is to request the garbage collector to perform a collection of all generations, which helps in freeing memory that is no longer in use by the application. Calling GC.Collect() triggers the garbage collection process immediately, though the actual timing of collection and memory cleanup may depend on the state of the memory and other factors within the .NET runtime. This can be particularly useful in scenarios where you expect there to be a significant amount of unused memory that can be reclaimed, such as after completing intensive memory operations or before entering a memory-sensitive phase of the application. Using this command should be done judiciously, as the .NET garbage collector is designed to work automatically, and manual invocation can lead to performance issues if overused. Normally, developers should rely on the garbage collector to manage memory efficiently without manual intervention. In contrast, the other options do not exist in the .NET Framework as valid methods for manual garbage collection. For instance, GC.Call() and GC.Run() are not recognized methods within the System.GC class, and GC.Clear() is also not a valid method for initiating garbage collection. Thus, the