GCCollectionMode Enumeration

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Specifies the behavior for a forced garbage collection.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

[SerializableAttribute]
public enum GCCollectionMode

Member nameDescription
Default

The default setting for this enumeration, which is currently Forced.

Forced

Forces the garbage collection to occur immediately.

Optimized

Allows the garbage collector to determine whether the current time is optimal to reclaim objects.

Use the GC.Collect method overload to specify the GCCollectionMode value.

The following example forces a garbage collection for generation 2 objects with the Optimized setting.

using System;

class Program
{
    static void Main(string[] args)
    {
        GC.Collect(2, GCCollectionMode.Optimized);
    }
}

Universal Windows Platform
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Return to top
Show: