To employ proper lifecycle management for its components Windsor uses release policy which is tasked with keeping track of components created by Windsor and releasing them when needed.
Its contract is defined by IReleasePolicy
interface and can be accessed (or changed) via ReleasePolicy
property of IKernel
var policy = container.Kernel.ReleasePolicy;
container.Kernel.ReleasePolicy = someOtherPolicy;
By default Windsor will use LifecycledComponentsReleasePolicy
which keeps track of all components that were created, and upon releasing them, invokes all their decommission lifecycle steps.
ℹ️ Always release components: When release policy tracks your components Garbage Collector is not able to reclaim them. That's why it's crucial that you always release your components you resolve (either via call to Resolve
/ResolveAll
or via a typed factory), especially ones that don't get released automatically. In particular this statement is true for transient components, since unless you release them, all their instances will live on until you dispose the container.
In cases when you don't want Windsor to track your components, you can resort to NoTrackingReleasePolicy
. It never tracks the components created, opting out of performing proper component decommission. Its usage is generally discouraged and targeted at limited scenarios of integration with legacy systems or external frameworks that don't allow you to properly release the components.