GetGeneration Method (Object)
Collapse the table of content
Expand the table of content

GC.GetGeneration Method (Object)


Returns the current generation number of the specified object.

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

public static int GetGeneration(
	object obj


Type: System.Object

The object that generation information is retrieved for.

Return Value

Type: System.Int32

The current generation number of obj.

Use this method to determine the age of an object, and then use that information with the Collect method to force the garbage collector to collect objects in the same generation. For example, use this method when you have a set of objects that are created as a group and that become inaccessible at the same time.

The following example demonstrates how to use the GetGeneration method to determine the age of an object. The example then performs garbage collections to clean up memory and compare the pre and post collection memory totals in the console.

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Windows Phone Silverlight
Available since 7.1
Return to top
© 2015 Microsoft