You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Memory leak when singleton in child container depend on singleton in parent via an interface #113
There seem to be a memory leak if a singleton registered in a child container depend on a singleton in the parent container via an interface. See example.
Using parentContainer.RegisterType<IA, A>(new ContainerControlledLifetimeManager()); solves the memory issue, but causes IA and A to resolve to different objects.
I would have expected some way to register both IA and A so they resolve the same object, and that all objects in a child container to be released when that child container is disposed.
Discovered this problem when upgrading from 4.0.1 to 5.8.6, but 5.8.11 has the same problem.
To Reproduce
publicinterfaceIA{}classA:IA{}classB{publicIAA{get;}publicB(IAa){A=a;}}classProgram{staticvoidMain(string[]args){using(varparentContainer=newUnityContainer()){parentContainer.RegisterType<A>(newContainerControlledLifetimeManager());parentContainer.RegisterType<IA,A>();using(varchildContainer=parentContainer.CreateChildContainer()){childContainer.RegisterSingleton<B>();varb=childContainer.Resolve<B>();Console.WriteLine("ia == a: "+(childContainer.Resolve<IA>()==childContainer.Resolve<A>()));}// B is kept alive by the parentContainerConsole.WriteLine("Press any key");Console.ReadKey();}}}
Additional context
Creating a memory snapshot after the child container has been disposed reveals the B object still being alive. dotMemory reports the retention path as following:
Activity
appel1 commentedon Oct 25, 2018
This looks like the same issue as #86.