[Breaking change]: GC.GetGeneration may return int.MaxValue for certain types of objects #35105
Closed
1 of 3 tasks
Labels
breaking-change
Indicates a .NET Core breaking change
🏁 Release: .NET 8
Work items for the .NET 8 release
📌 seQUESTered
Identifies that an issue has been imported into Quest.
Description
The following
GC
APIs:may return
int.MaxValue
for objects allocated on non-gc heaps (also referred as "frozen") where previously it used to return2
. When and how the runtime allocates objects on non-GC heaps is an internal implementation detail. A good example are most string literals, so e.g.might return
int.MaxValue
.Version
.NET 8 Preview 4
Previous behavior
GC.GetGeneration
used to return values in the range[0, 1, 2]
.New behavior
GC.GetGeneration
returns values in the range[0, 1, 2, int.MaxValue]
.Type of breaking change
Reason for change
Introduction of a new kind of heap (NonGC heap) that is slightly different from the existing ones (SOH, POH, LOH). More details can be found here dotnet/diagnostics#4156
Recommended action
Make sure
GC.GetGeneration
's return value is not used as an array indexer or any other case whereint.MaxValue
is not expectedFeature area
Core .NET libraries
Affected APIs
On the class
System.GC
:Associated WorkItem - 91241
The text was updated successfully, but these errors were encountered: