Source/Fusion/IntegrationTests/ControlLeakTests.cs
/// <summary>
/// Check that the object returned from the <paramref name="garbageFunc"/> delegate do not outlive
/// environment set up by <paramref name="environmentFactory"/>
/// </summary>
/// <typeparam name="TEnv">Type of environment</typeparam>
/// <param name="environmentFactory">Environment, which is kept alive while during forced GC</param>
/// <param name="garbageFunc">Object that we will assert whether it gets garbage collected or not</param>
Check that the object returned from the  delegate do not outlive
environment set up by
Check that the object returned from the delegate do not outlive environment set up by
[MethodImpl(MethodImplOptions.NoInlining)]
		static void AssertIsGarbageCollected<TEnv>(Func<TEnv> environmentFactory, Func<TEnv, object> garbageFunc)
		{
			Assert.That(
				garbageFunc.Target.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Length,
				Is.EqualTo(0),
				"Delegate should not capture anything");
			var env = environmentFactory();
			AssertIsGarbageCollected(env, garbageFunc);
			GC.KeepAlive(env);
		}
[ MethodImpl ( MethodImplOptions . NoInlining ) ] static void AssertIsGarbageCollected < TEnv > ( Func < TEnv > environmentFactory , Func < TEnv , object > garbageFunc ) { Assert . That ( garbageFunc . Target . GetType ( ) . GetFields ( BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) . Length , Is . EqualTo ( 0 ) , " " ) ; var env = environmentFactory ( ) ; AssertIsGarbageCollected ( env , garbageFunc ) ; GC . KeepAlive ( env ) ; }
Check that the object returned from the  delegate do not outlive
environment set up by
Check that the object returned from the delegate do not outlive environment set up by
environmentFactory
Func<TEnv>
Environment, which is kept alive while during forced GC
Environment which is kept alive while during forced GC
garbageFunc
Func<TEnv, object>
Object that we will assert whether it gets garbage collected or not
Object that we will assert whether it gets garbage collected or not
typeparam
Type of environment
Type of environment