3

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.


I am not the first one to encounter this problem

http://groups.google.com/group/castle-project-users/browse_thread/thread/bd287dd66b3a9d64/f48d740621508c64?lnk=gst&q=PerWebrequest#f48d740621508c64

fglez
  • 8,422
  • 4
  • 47
  • 78
mbergal
  • 635
  • 6
  • 13

1 Answers1

1

We found a similar issue in 2.1, seems to have been fixed along the way, upgrading should fix it.

Nariman
  • 6,368
  • 1
  • 35
  • 50