GCCollectionMode Enumeration
TOC
Collapse the table of content
Expand the table of content

GCCollectionMode Enumeration

 

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 4.5
.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:
© 2016 Microsoft