Skip to content

GC.WaitForPendingFinalizers again - #3222

Merged
timcassell merged 1 commit into
masterfrom
waitforpendingfinalizers
Aug 5, 2026
Merged

timcassell merged 1 commit into
masterfrom
waitforpendingfinalizers

Conversation

@timcassell

@timcassell timcassell commented Aug 5, 2026 •

Copy link
Copy Markdown
Collaborator

The engine calls GC.Collect a second time after GC.WaitForPendingFinalizers, presumably because a finalizer may allocate. But it doesn't wait for finalizers to complete the second time. Some types may revive themselves and allocate again every time the GC collects, like Gen2GcCallback (dotnet/runtime#101536). This causes a race condition where our allocation measurement may capture those background allocations. Adding an extra GC.WaitForPendingFinalizers should fix that race (of course it doesn't help if the benchmark causes the GC to run naturally, but that's unavoidable).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant