Reputation: 984
I am using Castle Windsor DI container in my WCF app server. In this case the lifetime is per-request: a new service instance is created, container is created and installed, some components are resolved, come work is done and all is disposed.
However, after some amount of requests there is increasing memory consumption of my app server. I was able to find out when I comment out the DI usage the memory problems disappear. But when I install the container and resolve some component, there are some "memory leaks". I found some articles and posts talking about lifecycles. But all of them are bound to container instance. Since my container lives just during the request there must be everything destroyed when disposing it.
My service implements IDisposable and in the Dispose method I call the container.Dispose as well. However memory usage grows on and on.
Using dotMemory profiler I can see there are survivors and new instances of ProxyGenerationOptions and some other classes.
Am I missing something? Why the container is not releasing all used memory after Dispose is called?
Upvotes: 2
Views: 491
Reputation: 11
I had a similar problem I solved it, when I created the proxy class, I served the ModuleScope object
public static class ProxyFactory
{
private static ModuleScope _moduleScope = new ModuleScope(false, false);
public static TClass CreateProxy<TClass>(TClass instance)
{
ProxyGenerator proxy = new ProxyGenerator(new DefaultProxyBuilder(_moduleScope));
List<Type> interfaces = new List<Type>();
interfaces.AddRange(instance.GetType().GetInterfaces());
TClass result = proxy.CreateClassProxyWithTarget(
instance.GetType(),
interfaces.ToArray(),
instance, ......
}
}
Upvotes: 1