0
votes

I'm using Castle Windsor to inject dependencies into several WCF services. We're also using Castle.Facilities.WcfIntegration.DefaultServiceHostFactory and castle's wcfFacility. Our services are hosted in IIS which gives me access to the Global.aspx events. All our components are registered with the transient lifecyle. Currently I register all the components in the container during the application_start event then dispose the container in the application_end.

However, after reading several blogs and some SO postings I'm starting to get worried that my solution is leaky. In other words, I think that releasing the container at application_end is going to cause memory to slowly leak from my application. I'm thinking about registering and releasing in the request_start and request_end or mabye session_start and session_end events. The problem I have is that I don't know where to 'keep' the container so I can release it after the session or request have ended. Has anyone come across this issue? And if so, how did you solve it? And does my solution sound right?

1
can you post the links that tells about memory leaks?VJAI

1 Answers

1
votes

Instantiating the container and registering everything at Application_Start is the right thing to do, and disposing the container at Application_End is also right.

Usually, when the word "memory leak" is said in connection with Castle Windsor, it is because of transient components not having their instances properly released, which in turn may cause instances to accumulate in the container. This is due to the fact that Windsor tracks the instances it hands to you if their dependency graphs contain anything with decommissioning involved (e.g. something that implements IDisposable).

Therefore, as a general rule with Windsor, you should always release what you resolve.

Never having used the WCF Facility, I am not really an expert on this, but I would be very surprised if it didn't properly release everything that it resolved - so I'm curious as to whether you know that there's a problem, or if you're just being cautious?