Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update return values for GC.GetGeneration #8993

Merged
merged 3 commits into from
May 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions xml/System/GC.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1083,22 +1083,24 @@ This method is most useful in monitoring scenarios for measuring the difference
<Docs>
<param name="obj">The object that generation information is retrieved for.</param>
<summary>Returns the current generation number of the specified object.</summary>
<returns>The current generation number of <paramref name="obj" />.</returns>
<returns>The current generation number of <paramref name="obj" />, or <see cref="F:System.Int32.MaxValue">Int32.MaxValue</see>.</returns>
<remarks>
<format type="text/markdown"><![CDATA[

## Remarks
Use this method to determine the age of an object, and then use that information with the <xref:System.GC.Collect%2A> 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.

Use this method to determine the age of an object, and then use that information with the <xref:System.GC.Collect%2A> 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.

Starting in .NET 8, this method might return <xref:System.Int32.MaxValue> for objects allocated on non-GC heaps. For more information, see [GC.GetGeneration might return Int32.MaxValue](/dotnet/core/compatibility/core-libraries/8.0/getgeneration-return-value).

## Examples
The following example demonstrates how to use the <xref:System.GC.GetGeneration%2A> 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.

:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.gc.collect int example/CPP/class1.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/GC/Overview/class1.cs" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System/GC/Overview/class1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.gc.collect int example/VB/class1.vb" id="Snippet1":::
The following example demonstrates how to use the <xref:System.GC.GetGeneration%2A> 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.

:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.gc.collect int example/CPP/class1.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/GC/Overview/class1.cs" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System/GC/Overview/class1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.gc.collect int example/VB/class1.vb" id="Snippet1":::

]]></format>
</remarks>
Expand Down Expand Up @@ -1150,17 +1152,22 @@ This method is most useful in monitoring scenarios for measuring the difference
<Docs>
<param name="wo">A <see cref="T:System.WeakReference" /> that refers to the target object whose generation number is to be determined.</param>
<summary>Returns the current generation number of the target of a specified weak reference.</summary>
<returns>The current generation number of the target of <paramref name="wo" />.</returns>
<returns>The current generation number of the target of <paramref name="wo" />, or <see cref="P:System.Int32.MaxValue" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[

## Remarks

Starting in .NET 8, this method might return <xref:System.Int32.MaxValue> for objects allocated on non-GC heaps. For more information, see [GC.GetGeneration might return Int32.MaxValue](/dotnet/core/compatibility/core-libraries/8.0/getgeneration-return-value).

## Examples
The following example demonstrates the use of the <xref:System.GC.GetGeneration%2A> method to determine the age of a weak reference object.

:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.GC.GetGenerationWeak Example/CPP/systemgcgetgenerationweak.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/GC/GetGeneration/systemgcgetgenerationweak.cs" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System/GC/GetGeneration/systemgcgetgenerationweak.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.GC.GetGenerationWeak Example/VB/systemgcgetgenerationweak.vb" id="Snippet1":::
The following example demonstrates the use of the <xref:System.GC.GetGeneration%2A> method to determine the age of a weak reference object.

:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.GC.GetGenerationWeak Example/CPP/systemgcgetgenerationweak.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/GC/GetGeneration/systemgcgetgenerationweak.cs" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System/GC/GetGeneration/systemgcgetgenerationweak.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.GC.GetGenerationWeak Example/VB/systemgcgetgenerationweak.vb" id="Snippet1":::

]]></format>
</remarks>
Expand Down