PerWebRequest is supposed to release components when request ends?

50 views
Skip to first unread message

SimoneB

unread,
Sep 8, 2009, 2:47:31 AM9/8/09
to Castle Project Users
Hi there,

I'm having some issues with managing release of components in a web
application built on ASP.NET WebForms. I set up a MVC pattern where at
the beginning of the request I inject my controllers into the pages.
The controllers are registered with PerWebRequest lifestyle, and as I
see from the code they are supposed to be released by the container
when the request ends. They have several dependencies with mixed
lifestyles, and usign a profiler I notice that many of them are not
actually released, instead at each request the number of instances
grows up.

I'm pretty sure I'm doing something wrong so I wanted a heads up to
what to look for to investigate this issue. The controllers - which
are the only one I resolve explicitly from the container - depend on
several other components with mixed lifestyles some of which implement
the IDisposable interface - which I know caused issues in the past due
to a problem about component burden which afaik should be fixed now.
Is there anything specific I should be looking for to investigate this
issue?

Thanks

Ken Egozi

unread,
Sep 8, 2009, 4:34:43 AM9/8/09
to castle-pro...@googlegroups.com
I *think* that whenever you explicitly Resolve, you have to explicitly Release.
Dependencies resolved by windsor will get released when they aren't needed any more.



--
Ken Egozi.
http://www.kenegozi.com/blog
http://www.delver.com
http://www.musicglue.com
http://www.castleproject.org
http://www.idcc.co.il - הכנס הקהילתי הראשון למפתחי דוטנט - בואו בהמוניכם

SimoneB

unread,
Sep 8, 2009, 6:07:07 AM9/8/09
to Castle Project Users
Looking at the code of PerWebRequest related classes, I thought that
the components resolved are automatically released. Not sure though.

On Sep 8, 10:34 am, Ken Egozi <egoz...@gmail.com> wrote:
> I *think* that whenever you explicitly Resolve, you have to explicitly
> Release.Dependencies resolved by windsor will get released when they aren't
> Ken Egozi.http://www.kenegozi.com/bloghttp://www.delver.comhttp://www.musicglue.comhttp://www.castleproject.orghttp://www.idcc.co.il- הכנס הקהילתי הראשון למפתחי דוטנט - בואו בהמוניכם

tom

unread,
Sep 8, 2009, 8:57:04 AM9/8/09
to Castle Project Users
I had a problem with it not releasing instances, and I got the latest
and compiled and it took care of the problem. This was just last
week. I really don't know if anything was changed, but for some
reason it took care of the problem. Just thought I would throw that
out there.
> > Ken Egozi.http://www.kenegozi.com/bloghttp://www.delver.comhttp://www.musicglue...הכנס הקהילתי הראשון למפתחי דוטנט - בואו בהמוניכם

Tuna Toksoz

unread,
Sep 8, 2009, 9:05:40 AM9/8/09
to castle-pro...@googlegroups.com
Can you both please try

container.ReleasePolicy = new Releasers.AllComponentsReleasePolicy();

SimoneB

unread,
Sep 8, 2009, 9:18:55 AM9/8/09
to Castle Project Users
Tuna, what's the purpose of doing that?

On Sep 8, 3:05 pm, Tuna Toksoz <tehl...@gmail.com> wrote:
> Can you both please try
> container.ReleasePolicy = new Releasers.AllComponentsReleasePolicy();
>
> Tuna Toksöz
> Eternal sunshine of the open source mind.
>
> http://devlicio.us/blogs/tuna_toksozhttp://tunatoksoz.comhttp://twitter.com/tehlike
> >http://www.kenegozi.com/bloghttp://www.delver.comhttp://www.musicglue...כנס

Tuna Toksoz

unread,
Sep 8, 2009, 9:21:45 AM9/8/09
to castle-pro...@googlegroups.com
I am not yet sure as i didn't have any time since i last looked at it, but it is related to component burden of several months ago.
It solved one similar problem with components not being released, might help.

Let me know if it works, if it does, i will ask for a favor from any of you.

SimoneB

unread,
Sep 9, 2009, 2:32:00 AM9/9/09
to Castle Project Users
I think I finally got it, and it seems it's the burden issue once
again, unless I'm missing something - which is likely, btw.

I have my controller like so:

class Controller
{
public Controller(INonDisposableDependency
nonDisposableDependency) { ... }

public Controller(IDisposableDependency disposableDependency)
{ ... }
}

I'm running on the trunk. At each request I resolve a controller from
the container and don't explicitly do anything else on the container
itself.

Using the PerWebRequest lifestyle on the controller and independent
from the lifestyle of the dependency, if I register a non disposable
dependency into the container (the first constructor is called), at
the end of the request both controller and dependency are released and
collected when the GC runs.

If I register a disposable dependency, instead (second constructor
called), I see the number of instances of both controller and
dependency growing up. The controller has roots in the microkernel,
Burden property, and the dependency in both the Controller and the
microkernel as well.

All these considerations are made with the help of a profiler.

On Sep 8, 3:21 pm, Tuna Toksoz <tehl...@gmail.com> wrote:
> I am not yet sure as i didn't have any time since i last looked at it, but
> it is related to component burden of several months ago.It solved one
> similar problem with components not being released, might help.
>
> Let me know if it works, if it does, i will ask for a favor from any of you.
>
> Tuna Toksöz
> Eternal sunshine of the open source mind.
>
> http://devlicio.us/blogs/tuna_toksozhttp://tunatoksoz.comhttp://twitter.com/tehlike
>
> On Tue, Sep 8, 2009 at 9:18 AM, SimoneB <simone.bus...@gmail.com> wrote:
>
> > Tuna, what's the purpose of doing that?
>
> > On Sep 8, 3:05 pm, Tuna Toksoz <tehl...@gmail.com> wrote:
> > > Can you both please try
> > > container.ReleasePolicy = new Releasers.AllComponentsReleasePolicy();
>
> > > Tuna Toksöz
> > > Eternal sunshine of the open source mind.
>
> >http://devlicio.us/blogs/tuna_toksozhttp://tunatoksoz.comhttp://twitt...

SimoneB

unread,
Sep 9, 2009, 2:34:31 AM9/9/09
to Castle Project Users
As an additional detail, configuring the container with
AllComponentsReleasePolicy, as suggested by Tuna, doesn't change
anything, while using NoTrackingReleasePolicy I get the correct
behavior.
Reply all
Reply to author
Forward
0 new messages