3
votes

I do have an architectural problem (and besides I am not very familiar with Castle Windsor, which is used as a container for my application).

I have a Web application that implements the unit of work design pattern. UnitOfWork implements the IDisposable interface.

I see no particular reason for the actions done in the Dispose method of the UnitOfWork (those actions are already done somewhen at an earlier moment).

Also, all my components are instantiated using the transient lifecycle.

Almost any component is also using a repository instance, which is also transient and also implements IDisposable (and again, no particular reason for that).

Also most of those components are also used by some desktop applications.

The problem I met was the memory leak due to the transient components implementing IDisposable, as I read here: http://nexussharp.wordpress.com/2012/04/21/castle-windsor-avoid-memory-leaks-by-learning-the-underlying-mechanics/ .

I also noticed Dispose any way being never called, neither from the web application nor from the client ones (and actually found more posts that it would be called when Release is called on the component).

One option of fixing the memory leak problem (and without using the NoTrackReleasePolicy!) was to actually remove implementing of the IDisposable. But I guess this would be similar to specifying the NoTrackReleasePolicy, which could lead to even bigger problems than memory leak (although I do no see how ?) - so this is my first question.

I also tried specifying PerWebRequest instead of Transient, but how would be the behaviour of the components for the desktop applications in this case, since there's no web request\context ? That is my second question.

One more thing which I would not like to take into consideration is manually calling release for every component I resolve ...

Any ideas of solving the issue in the most safe\elegant\with less changes way would be much appreciated ...

1

1 Answers

4
votes

There are few steps you should take.

  1. stop whatever you're doing

  2. learn about the tools you're trying to use, especially the part about lifestyles

  3. Make sure you're understanding why Windsor is tracking the components

  4. Make sure you're understanding why tracking is important and NoTrackingReleasePolicy is a Bad Idea™

  5. Make sure you understand how Unit of Work works.

Now that you know a few basics, if you're looking for inspiration as to how solve this in web have a look at this tutorial which shows how to implement UoW with Windsor on the web.

On desktop it's more complicated and scenario dependant, just make sure you're not trying to reuse your registration code between the two apps.