Given
public class a : IDisposable
{
public static int counter;
public a()
{
counter++;
}
~a()
{
counter--;
}
public void Dispose()
{
}
}
With registration:
application_container = new WindsorContainer( );
application_container.Register( Component.For<a>( ).ImplementedBy<a>( ).LifeStyle.PerWebRequest );
Proper stuff in web.config:
<add name="PerRequestLifestyle"
type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule,
Castle.MicroKernel"/>
Using version of Castle built from SVN. With web page code:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GC.Collect( 2 );
var a = Global.application_container.Resolve<Global.a>();
Response.Write( Global.a.counter.ToString() );
}
}
I get that ~a() is not called and RedGate profiler shows that a is not being collected, the reference to it stuck in AllComponentsReleasePolicy.instance2burden.