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

[Breaking change]: GC.GetGeneration may return int.MaxValue for certain types of objects #35105

Closed
1 of 3 tasks
EgorBo opened this issue Apr 23, 2023 · 0 comments · Fixed by #35228
Closed
1 of 3 tasks
Assignees
Labels
breaking-change Indicates a .NET Core breaking change 🏁 Release: .NET 8 Work items for the .NET 8 release doc-idea Indicates issues that are suggestions for new topics [org][type][category] Pri1 High priority, do before Pri2 and Pri3 📌 seQUESTered Identifies that an issue has been imported into Quest.

Comments

@EgorBo
Copy link
Member

EgorBo commented Apr 23, 2023

Description

The following GC APIs:

int GetGeneration(object obj);
int GetGeneration(WeakReference wo)

may return int.MaxValue for objects allocated on non-gc heaps (also referred as "frozen") where previously it used to return 2. 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.

int gen = int GetGeneration("string");

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

  • Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
  • Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code may require source changes to compile successfully.
  • Behavioral change: Existing binaries may behave differently at run time.

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 where int.MaxValue is not expected

Feature area

Core .NET libraries

Affected APIs

On the class System.GC:

int GetGeneration(object obj);
int GetGeneration(WeakReference wo)

Associated WorkItem - 91241

@EgorBo EgorBo added doc-idea Indicates issues that are suggestions for new topics [org][type][category] breaking-change Indicates a .NET Core breaking change Pri1 High priority, do before Pri2 and Pri3 labels Apr 23, 2023
@dotnet-bot dotnet-bot added the ⌚ Not Triaged Not triaged label Apr 23, 2023
@gewarren gewarren added 🏁 Release: .NET 8 Work items for the .NET 8 release and removed ⌚ Not Triaged Not triaged labels Apr 24, 2023
@ghost ghost added the in-pr This issue will be closed (fixed) by an active pull request. label May 2, 2023
@ghost ghost removed the in-pr This issue will be closed (fixed) by an active pull request. label May 4, 2023
@gewarren gewarren added the 🗺️ reQUEST Triggers an issue to be imported into Quest. label May 18, 2023
@github-actions github-actions bot added 📌 seQUESTered Identifies that an issue has been imported into Quest. and removed 🗺️ reQUEST Triggers an issue to be imported into Quest. labels May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Indicates a .NET Core breaking change 🏁 Release: .NET 8 Work items for the .NET 8 release doc-idea Indicates issues that are suggestions for new topics [org][type][category] Pri1 High priority, do before Pri2 and Pri3 📌 seQUESTered Identifies that an issue has been imported into Quest.
Projects
No open projects
Status: Done
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants