views:

71

answers:

1

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.

A: 

This is not an answer, just 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&amp;q=PerWebrequest#f48d740621508c64

mbergal