Search code examples
c#garbage-collection

C# - Call GC.Collect() manually (Disable background GC)


I want to compare performance between my garbage collection at C++ and C#'s. It is possible to call GC.Collect() manually? (I want to run it at specific moments.)


Solution

  • There is no way to disable the garbage collection in C# outside of using unsafe code. You can force the garbage collector to run by calling System.GC.Collect() or one of its various overloads.

    Full MSDN Documentation