/// <summary>Forces an immediate garbage collection from generation zero through a specified generation.</summary> /// <param name="generation">The number of the oldest generation that garbage collection can be performed on. </param> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="generation" /> is not valid. </exception> /// <filterpriority>1</filterpriority> public static void Collect(int generation) { if (generation < 0) { throw new ArgumentOutOfRangeException("generation"); } GC.InternalCollect(generation); }
/// <summary>Forces an immediate garbage collection of all generations. </summary> /// <filterpriority>1</filterpriority> public static void Collect() { GC.InternalCollect(GC.MaxGeneration); }