Skip to content

Commit

Permalink
Fixed test with weak reference
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-danilov committed Jun 27, 2016
1 parent 8847a31 commit cd79fee
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/Castle.Windsor.Tests/Lifestyle/ScopedLifestyleTestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,23 @@ 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;
GC.Collect();
var weakUdt = GetWeakReferenceToDisposableFoo();
GC.Collect();
Assert.IsFalse(weakUdt.IsAlive);
}
}

[Test]
// 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()
{
Container.Register(Component.For<DisposableFoo>().LifeStyle.Scoped(),
Expand Down

0 comments on commit cd79fee

Please sign in to comment.