How to force full garbage collection in .NET 4.x?
问题 I've a problem with WeakReferences in .NET 4.x, I was running tests to make sure some objects were not referenced anymore (using WeakReferences) and I noticed the behavior is not consistent across framework versions: using System; using System.Text; using NUnit.Framework; [TestFixture] public class WeakReferenceTests { [Test] public void TestWeakReferenceIsDisposed() { WeakReference weakRef = new WeakReference(new StringBuilder("Hello")); GC.Collect(); GC.WaitForPendingFinalizers(); GC