Skip to content

Commit 9e042a3

Browse files
committed
Added comment to not call GC.Collect.
1 parent 48c5591 commit 9e042a3

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/BenchmarkDotNet/Engines/GcStats.cs

+2
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ public static GcStats FromForced(int forcedFullGarbageCollections)
145145
if (RuntimeInformation.IsWasm)
146146
return null;
147147

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

0 commit comments

Comments
 (0)