Skip to content

Commit

Permalink
Merge pull request #138 from ivan-danilov/gc-changes-fix
Browse files Browse the repository at this point in the history
Fixed test with weak reference in .NET 4.6.x
  • Loading branch information
hammett authored Jun 27, 2016
2 parents 8847a31 + 371312a commit b6dcb35
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Castle.Windsor.Tests/Lifestyle/ScopedLifestyleTestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,22 @@ public void Transient_depending_on_scoped_component_is_not_tracked_by_the_contai

using (Container.BeginScope())
{
var udf = Container.Resolve<UsesDisposableFoo>();
var weakUdt = new WeakReference(udf);
udf = null;
var weakUdt = GetWeakReferenceToDisposableFoo();
GC.Collect();
Assert.IsFalse(weakUdt.IsAlive);
}
}

// method is needed because since 4.6.x under debug configuration local variables are not
// considered for garbage collection; hence if method is inlined - test will fail
private WeakReference GetWeakReferenceToDisposableFoo()
{
var udf = Container.Resolve<UsesDisposableFoo>();
var weakUdt = new WeakReference(udf);
udf = null;
return weakUdt;
}

[Test]
public void Transient_depending_on_scoped_component_is_not_tracked_by_the_release_policy()
{
Expand Down

0 comments on commit b6dcb35

Please sign in to comment.