I’m using Windsor as IoC through the
public sealed class WindsorContainerAdapter : IContainerAdapter, IDisposable, IRelease
I implemented IRelease interface to implement the RRR pattern correctly as suggest in your StackOverflow post
my sample object graph is the following
- HelloService (SS service)
- MyComp1
- MyComp2
I do register my custom component in windsor
MyComp1 → LifestyleTransient
MyComp2 → LifestylePerWebRequest
as per SS wiki The IoC container · ServiceStack/ServiceStack Wiki · GitHub
the services are still registered in Funq but all their dependencies are resolved by the ContainerAdapter specified
Due to IRelease interface on WindsorContainerAdapter the Release method within AppHost has been called
var iocAdapterReleases = Container.Adapter as IRelease;
if (iocAdapterReleases != null)
{
iocAdapterReleases.Release(instance);
}
else
{
var disposable = instance as IDisposable;
if (disposable != null)
disposable.Dispose();
}
but the “instance” object is HelloService, not MyComp1: that leads to have a zombie object(the instance of MyComp1 resolved through Windsor since that’s a dependecy oh HelloService) on each request: since the Release has been invoke on a an instance not created by Windsor is useless, while it should be called on each instance created through windsor
Since WindsorAdapter implements IRelease, HelloService will be tried to be disposed by windsor, but since it has not been created by Windsor, nothing happend: even worst the HelloService will not be disposed at all!
From the wiki
So to have resolved services released back into your IOC, implement the IRelease interface on your IContainerAdapter, e.g:
Why Windsor should dispose an instance (HelloService) that has not been Register neither so Resolved by itself???
In the other hand, MyComp2 will be disposed correctly since its lifestyle is PerWebRequest, so windsor take care of releasing it by itself with no explicit Release called on the instance.
If I change the MyComp1 lifestyle fromTransient to PerWebRequest it will be disposed correctly as well…
Now the question is: since SS/Funq invoke Windosor Resolve for MyComp1( since that’s a dependency of HelloService) IT SHOULD some how invoke Release as well (I assume throught the Release method within AppHost)
According to the “composition root” pattern, the Resolve/Release should be called only on the SS Services (HelloService in my sample)
Apparently the IRelease on WindsorContainerAdapter seems to having the following issues:
-
not Releasing the component Resolved by SS/service dependencies → zombie objects = memory leak
-
prevent the SS services disposing → what that gonna cause?
what am I missing here?