If you are considering GC issues in an app, I think the reference code you should look at now is Roslyn and how it uses pooled ImmutableArrays to work with immutable collections almost without allocation overhead in most areas.<p>Most GC churn in most applications (I would think) is down to Linq and collection use.<p><a href="https://github.com/dotnet/roslyn/blob/master/src/ExpressionEvaluator/Core/Source/ResultProvider/Helpers/ArrayBuilder.cs" rel="nofollow">https://github.com/dotnet/roslyn/blob/master/src/ExpressionE...</a>
I wonder how much of the advice is still important with the improvements .NET GC has received over the decades [1] [2]<p>[1]
<a href="http://scottdorman.github.io/2008/11/07/clr-4.0-garbage-collection-changes/" rel="nofollow">http://scottdorman.github.io/2008/11/07/clr-4.0-garbage-coll...</a><p>[2]
<a href="https://blogs.msdn.microsoft.com/dotnet/2012/07/20/the-net-framework-4-5-includes-new-garbage-collector-enhancements-for-client-and-server-apps/" rel="nofollow">https://blogs.msdn.microsoft.com/dotnet/2012/07/20/the-net-f...</a>
Back in 2005-2006 we ran into significant issues with the GC and pinned memory related to Windows sockets when building a networked server for XMPP. I believe the GC has improved since then for that scenario, but it was a big surprise when it happened. It was a classic case of a leaky abstraction.<p><a href="http://blog.jdconley.com/2006/06/how-to-build-scalable-net-server.html" rel="nofollow">http://blog.jdconley.com/2006/06/how-to-build-scalable-net-s...</a>
For those interested in more details about .NET garbage collector here is some reading.<p>Garbage Collection Overview<p><a href="https://msdn.microsoft.com/en-us/library/0xy59wtx(v=vs.110).aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/0xy59wtx(v=vs.110)....</a><p>Fundamentals of garbage collection<p><a href="https://msdn.microsoft.com/en-us/library/ee787088(v=vs.110).aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/ee787088(v=vs.110)....</a><p>Visualising the .NET Garbage Collector<p><a href="http://mattwarren.org/2016/06/20/Visualising-the-dotNET-Garbage-Collector/" rel="nofollow">http://mattwarren.org/2016/06/20/Visualising-the-dotNET-Garb...</a><p>Clr Book of the runtime : Garbage Collection<p><a href="https://github.com/dotnet/coreclr/blob/master/Documentation/botr/garbage-collection.md" rel="nofollow">https://github.com/dotnet/coreclr/blob/master/Documentation/...</a><p>Maoni Stephen's Blog<p><a href="https://blogs.msdn.microsoft.com/maoni" rel="nofollow">https://blogs.msdn.microsoft.com/maoni</a><p><a href="https://blogs.msdn.microsoft.com/maoni/2004/06/15/using-gc-efficiently-part-1/" rel="nofollow">https://blogs.msdn.microsoft.com/maoni/2004/06/15/using-gc-e...</a><p><a href="https://blogs.msdn.microsoft.com/maoni/2004/09/25/using-gc-efficiently-part-2/" rel="nofollow">https://blogs.msdn.microsoft.com/maoni/2004/09/25/using-gc-e...</a><p><a href="https://blogs.msdn.microsoft.com/maoni/2004/12/19/using-gc-efficiently-part-3/" rel="nofollow">https://blogs.msdn.microsoft.com/maoni/2004/12/19/using-gc-e...</a><p><a href="https://blogs.msdn.microsoft.com/maoni/2005/05/06/using-gc-efficiently-part-4/" rel="nofollow">https://blogs.msdn.microsoft.com/maoni/2005/05/06/using-gc-e...</a><p>There is also a refactoring effort to standardize the GC<->EE interface<p><a href="https://github.com/dotnet/coreclr/projects/3" rel="nofollow">https://github.com/dotnet/coreclr/projects/3</a><p>I would link to the source code of the GC itself, but it's a single 35KSLOC file.
This is timely as I'm troubleshooting a .NET app with randomly long garbage collection times. I'm just the sysadmin in this scenario, without access to the code, so I'm approaching it from Splunk and AppDynamics. If anyone has suggestions beyond this article, I'd appreciate it :)