BenchmarkDotNet
BenchmarkDotNet copied to clipboard
Consider changing `Consume` to not hold onto references for very long
Currently some of the Consume methods stash the reference passed to them in a local field, keeping the object alive as long as the consume object itself remains live.
https://github.com/dotnet/BenchmarkDotNet/blob/b78ec96631c5065895255165b7113bf5062aa407/src/BenchmarkDotNet/Engines/Consumer.cs#L98-L109
If that object roots a large object graph or large array allocation it can alter GC behavior and impact benchmark timing.
Consider either immediately over-writing the local field with null or nulling out this field at the end of measurement intervals.
I actually ran into this while attempting to measure survived memory in #1596. I ended up adding a Clear method that I ran at the end of the benchmark. Unfortunately that PR never got merged (I guess cause .Net Core still hasn't fixed the measurement error).