Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
GCCollectionMode Enumeration
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
Supported by Portable Class LibraryDefaultThe default setting for this enumeration, which is currently Forced.
Supported by Portable Class LibraryForcedForces the garbage collection to occur immediately.
Supported by Portable Class LibraryOptimizedAllows 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);
    }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5 SP1, 3.0 SP1, 2.0 SP1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library
Show:
© 2015 Microsoft