Skip to content

Commit

Permalink
Added comment to not call GC.Collect.
Browse files Browse the repository at this point in the history
  • Loading branch information
timcassell committed May 26, 2024
1 parent 48c5591 commit 9e042a3
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/BenchmarkDotNet/Engines/GcStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ public static GcStats FromForced(int forcedFullGarbageCollections)
if (RuntimeInformation.IsWasm)
return null;

// Do NOT call GC.Collect() here, as it causes finalizers to run and possibly allocate. https://github.com/dotnet/runtime/issues/101536#issuecomment-2077533242
// Instead, we call it before we start the measurement in the Engine.
#if NET6_0_OR_GREATER
return GC.GetTotalAllocatedBytes(precise: true);
#else
Expand Down

0 comments on commit 9e042a3

Please sign in to comment.