3
votes

I'm coming from a background with Java and Spring, and I am rather new with Castle Windsor. I've read that it is important to know when transient components will be released by Castle since it tracks all components created. I'm having a hard time understanding when my components will be released though. Here is the basics of my model:

Singleton -> Singleton Typed Factory -> Transient Objects

If I release the first singleton in this chain will all the transient objects created by the typed factory be released? Is there any API call I can make to check if this is the case? I can't find any comprehensive API documentation on the Castle Windsor website. The documentation I did find just doesn't seem clear to me.

Edit: My problem boils down to two main questions.

  1. If I have a singleton object (A) that depends on a singleton typed factory (B) and I release singleton A will that actually release B? The blog post mentioned in the answer below says that calls to release on singleton objects are ignored, so my assumption is no it will not be released.
  2. If I have a singleton typed factory that is used by multiple web requests simultaneously to create transient objects and is released by one of the web requests, will all the transient objects be released, whether they were created from that web request or not? It almost seems like making typed factories per web request or transient lifestyle is better.
1
In your edit, you mention Transient components inside web requests. If this is for a web application, why not use the PerWebRequest lifestyle (which has a well-defined endpoint at which the components will be released)?PatrickSteele
@PatrickSteele If I have a PerWebRequest lifestyle typed factory will that automatically release all the transient objects it has created at the end of the request?jjathman

1 Answers

8
votes

Here's a detailed post that explains how Windsor tracks objects and when you need to call Release: http://kozmic.pl/2010/08/27/must-i-release-everything-when-using-windsor/

Updates to your updates

  1. Any release on a singleton is ignored so, yes, you're correct -- it will not be released.

  2. You only need to worry about Releasing components you specifically resolved. If it was resolved by Windsor (via Typed Factory Facility, sub-dependency resolver, etc...) don't worry about it.