NServiceBus/NServiceBus — pull request #543 by peterbeams (2012-07-20 12:35:29+00:00)
Title: Develop

The Castle Windsor container implements a "Register Resolve Release" pattern for components. When using the Castle builder with NServiceBus, the UnicastBus indirectly calls Resolve on the container to build a list of MessageModules that are run before and after each message is handled. When the messages modules have been used (either HandleEndMessage or HandleError is called), the container is never called to Release the messages modules that were built. Castle tracks the message modules and their dependencies until they are explicitly released, because that never happens it leads to a memory leak as everytime a message module is loaded it is never cleaned up.

I've added a Release method to the IContainer and IBuilder interfaces and called it where I think it is needed in the UnicastBus.

http://blog.ploeh.dk/2010/09/29/TheRegisterResolveReleasePattern.aspx
http://nexussharp.wordpress.com/2012/04/21/castle-windsor-avoid-memory-leaks-by-learning-the-underlying-mechanics/